sadpandajoe opened a new pull request, #45872:
URL: https://github.com/apache/superset/pull/45872

   ### 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 OR ANIMATED GIF
   
   Before: fill the PostgreSQL form, switch to the URI form and back; host, 
port, database, username and password are empty again. After: the values 
entered are still present after the round trip, and a URI typed in the URI form 
is still there after switching to the dynamic form and back. Screenshots and a 
recording of both flows follow in an update to this description.
   
   ### 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:
   - [x] Changes UI
   - [ ] Includes DB Migration (follow approval process in 
[SIP-59](https://github.com/apache/superset/issues/13351))
     - [ ] 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
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to