Sponsored Content
Skip to content

[Product] MongoDB auth_source has no form field, and a config carrying it is silently dropped on save #638

Description

@Timev

Summary

auth_source was added to the MongoDB connection schema this morning in #625. It has no input in the connection form, and a config that carries it loses it on the next structured-form save.

Found while writing SPEC_MONGODB_TLS_SRV.md for #626. Verified against origin/dev @ f6851eb.

Evidence

git grep -n "auth_source" origin/dev -- datanika/ui/

returns nothing. Concretely:

  • ui/components/connection_config_fields.py::mongodb_fields() renders host, port, user, password, database. No auth_source control.
  • ui/state/connection_state.py::_build_config(), mongodb branch (lines 754–764), writes exactly those five keys.
  • ui/state/connection_state.py::_populate_form_from_config(), mongodb branch, reads exactly those five keys.

The defect

auth_source is reachable only via the raw-JSON escape hatch, and it does not survive contact with the structured form:

  1. User sets {"auth_source": "orders", …} through raw JSON. Runs work.
  2. Later they open that connection in the structured form — to fix a typo in the host, say — and click Save.
  3. _build_config() rebuilds the config from its five fields. auth_source is gone.
  4. build_connection_uri re-defaults the absent key to admin, and the next run fails authentication.

The user changed a hostname and their authentication silently reverted. Nothing in the UI indicates a field was discarded.

This is exactly the population #550 exposed the setting for: users whose MongoDB user lives inside the target database rather than in admin.

Why the existing test did not catch it

tests/test_services/test_mongodb_auth_source.py::TestTheDefaultIsDeclared::test_it_is_exposed_in_the_connection_schema carries the docstring "A setting with no surface is the core#499 mistake." It asserts on CONFIG_SCHEMAS["mongodb"]["properties"].

But connection_schemas.py and the Reflex form are two hand-maintained string sources with no code linking them — the schema module's own docstring still describes UI form rendering as (future). So the test asserts the schema surface while the mistake it was written to prevent lives in the UI surface. It passes, and the setting has no surface.

Scope is wider than one key

_build_config() and _populate_form_from_config() are hand-written, per-type, and exhaustive-by-omission for every connector. Any config key present in one and absent from the other is silently dropped on save. auth_source is the instance that exists today; the same shape will reproduce for tls and srv in #626 if only one side is written.

Fix

Product's spec for #626 covers the auth_source input, since it is one field in the same function and the field TLS/SRV has to compose with. Filing this separately so the defect is tracked even if delivery splits, and because the general case is bigger than #626:

  1. Add the auth_source input to mongodb_fields(), plus form_auth_source + setter.
  2. Add the line to both _build_config() and _populate_form_from_config().
  3. Regression test written red-first: a config carrying auth_source, loaded into the form and saved unchanged, retains every key. It must fail against current dev.
  4. Worth considering: a generic guard that round-trips each connector type's CONFIG_SCHEMAS properties through _populate_form_from_config()_build_config() and asserts nothing is lost. That catches the whole class rather than this instance, and would have caught this one on the day MongoDB Test Connection ignores auth_source — fails on connections whose runs succeed (core#550 gap) #625 merged.

Severity

Low urgency (0 users, and the raw-JSON path is not a documented flow), but it is silent data loss in a credential-adjacent setting, and item 4 is the durable version.

Metadata

Metadata

Assignees

No one assigned

    Labels

    shipped-to-prodReferencing commit is already deployed to production. Close it if its acceptance criteria are met.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions