Skip to content

fix(database): keep entered values when switching connection mode - #45872

Open
sadpandajoe wants to merge 2 commits into
masterfrom
fix-database-modal-mode-toggle-state
Open

sadpandajoe wants to merge 2 commits into
masterfrom
fix-database-modal-mode-toggle-state

Conversation

@sadpandajoe

@sadpandajoe sadpandajoe commented Oct 30, 2026 •

Copy link
Copy Markdown
Member

SUMMARY

In the "Connect a database" modal, switching between the dynamic form and "Connect this database with a SQLAlchemy URI string instead" (and back) discarded everything the user had entered: host, port, database, username, password, a typed SQLAlchemy URI, and the engine metadata the form relies on (for example which Advanced options are offered). Only the display name survived, so a long password or a pasted URI had to be entered again with no warning.

Root Cause

The reducer case that handles the mode switch (ActionType.ConfigMethodChange in dbReducer) returned only the keys sent by the two toggle buttons (engine, configuration_method, database_name), replacing the entire modal state instead of merging into it. That is why the display name, which the buttons copy by hand, was the only value that survived. The replace semantics date from when the case shared a branch with the engine-selection action, where starting from a blank form was correct; once the toggle became reachable from a populated form, nothing exercised it.

The case now merges the payload onto the previous state, falling back to the previous database_name and engine if the payload leaves them undefined. The two toggle buttons are unchanged.

Stale values that remain in state cannot reach the saved database: on create and update the backend builds sqlalchemy_uri from parameters only when configuration_method is dynamic_form (overwriting any existing URI), and ignores parameters otherwise.

Not addressed here

Switching from the dynamic form to the URI form still does not fill in the SQLAlchemy URI from the values typed so far. Nothing on the client builds a URI from parameters, and no API returns one without creating or updating the database, so this needs backend support and is left for a separate change.

BEFORE/AFTER SCREENSHOTS

Before After
Before — PostgreSQL step 2 of the Connect a database modal after filling the form, switching to the SQLAlchemy URI form and back to the dynamic form After — PostgreSQL step 2 of the Connect a database modal after filling the form, switching to the SQLAlchemy URI form and back to the dynamic form

Before video: https://gist.githubusercontent.com/sadpandajoe/ed885611403e98253fe4bdbde8526b4f/raw/298709d02d5b28fd57f6c603fc8daf33c6d53aff/before.mp4

Before — PostgreSQL step 2 of the Connect a database modal after filling the form, switching to the SQLAlchemy URI form and back to the dynamic form recording

After video: https://gist.githubusercontent.com/sadpandajoe/ed885611403e98253fe4bdbde8526b4f/raw/298709d02d5b28fd57f6c603fc8daf33c6d53aff/after.mp4

After — PostgreSQL step 2 of the Connect a database modal after filling the form, switching to the SQLAlchemy URI form and back to the dynamic form recording

TESTING INSTRUCTIONS

Automated:

npm run test -- src/features/databases/DatabaseModal/index.test.tsx

Four new tests fail on the parent commit and pass with this change: two that drive the real modal (dynamic form values and a typed URI each survive a round trip between the two modes) and two reducer tests for ConfigMethodChange (previous fields preserved with the new configuration_method applied; fallback to the previous database_name and engine).

Manual:

  1. Open Settings > Database Connections > + Database and choose PostgreSQL.
  2. Fill in host, port, database name, username, password and display name.
  3. Click "Connect this database with a SQLAlchemy URI string instead", then "Connect this database using the dynamic form instead".
  4. Confirm every value entered in step 2 is still present.
  5. Repeat in the other direction: type a SQLAlchemy URI, switch to the dynamic form and back, and confirm the URI is still there.

ADDITIONAL INFORMATION

  • Has associated issue:
  • Required feature flags:
  • Changes UI
  • Includes DB Migration (follow approval process in SIP-59)
    • Migration is atomic, supports rollback & is backwards-compatible
    • Confirm DB migration upgrade and downgrade tested
    • Runtime estimates and downtime expectations provided
  • Introduces new feature or API
  • Removes existing feature or API

Switching between the dynamic form and the SQLAlchemy URI form in the
database modal replaces the whole form state, discarding typed values.
Add tests that fill each form, toggle to the other and back, and assert
the typed values are still present.
Switching between the dynamic form and the SQLAlchemy URI form in the
database modal replaced the whole form state with the three keys sent by
the toggle buttons, discarding every typed value (and the engine metadata
the form relies on). Merge the toggle payload onto the previous state
instead, falling back to the previous database name and engine when the
payload leaves them undefined.
@codecov

codecov Bot commented Oct 30, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 65.62%. Comparing base (a8c13c6) to head (5665540).

Additional details and impacted files
@@           Coverage Diff           @@
##           master   #45872   +/-   ##
=======================================
  Coverage   65.62%   65.62%           
=======================================
  Files        3069     3069           
  Lines      205661   205663    +2     
  Branches    48336    48338    +2     
=======================================
+ Hits       134956   134965    +9     
+ Misses      67624    67617    -7     
  Partials     3081     3081           
Flag Coverage Δ
javascript 80.95% <100.00%> (+<0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@sadpandajoe
sadpandajoe marked this pull request as ready for review October 30, 2026 02:24
@codeant-ai-for-open-source

Copy link
Copy Markdown
Contributor

CodeAnt  CodeAnt PR Risk

🟢  Low Risk

  • The PR appears safe to merge; no actionable issues were identified in the review.

Assessed commit: 5665540ca991

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants