[DBA-141] Add field validations on datasource adding#81
Conversation
Add frontend validation for datasource names in both the Streamlit UI and CLI workflow. Names with spaces, special characters, and other invalid patterns are rejected with clear error messages before submission instead of failing on the backend. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Use the agent's source name pattern (^[A-Za-z][A-Za-z0-9_]*$) for the last segment so names work unquoted in SQL. Add validate_port() and validate_hostname() validators, applied automatically to config fields based on their key name and type. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Adds shared datasource field validation to prevent invalid datasource names/config values from being accepted in the Streamlit UI and interactive CLI, improving feedback before submission and aligning test fixtures with the stricter naming rules.
Changes:
- Introduces a shared validation module for datasource names plus host/port validation helpers.
- Adds pre-submit validation in Streamlit datasource management and in the interactive CLI add workflow.
- Adds unit tests for the shared validation module and updates e2e test fixtures to use underscore-based datasource names/ids.
Reviewed changes
Copilot reviewed 9 out of 9 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
src/databao_cli/features/datasource/validation.py |
New shared validation helpers for datasource name, hostname, and port. |
src/databao_cli/workflows/datasource/add.py |
Loops until a valid datasource name is entered in the CLI workflow. |
src/databao_cli/features/ui/components/datasource_manager.py |
Validates datasource name/type before add/verify; validates required config fields before add. |
src/databao_cli/features/ui/components/datasource_form.py |
Adds config-field validation (required fields + host/port checks). |
tests/test_datasource_validation.py |
New unit tests for the shared validation module. |
e2e-tests/tests/resources/sqlite_introspections.yaml |
Updates datasource id/comment to match underscore naming. |
e2e-tests/tests/resources/duckdb_introspections.yaml |
Updates datasource id/comment to match underscore naming. |
e2e-tests/src/databases/sqlite_utils.py |
Updates default sqlite datasource name to underscore form. |
e2e-tests/src/databases/duckdb_utils.py |
Updates default duckdb datasource name to underscore form. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
gasparian
left a comment
There was a problem hiding this comment.
The "Save" path for existing datasources (datasource_manager.py:196-208) doesn't run any validation before persisting. A user could edit a datasource, clear a required field or type garbage into the port/host inputs, hit Save, and the invalid config gets written to disk without complaint. Seems like validate_config_fields() should be called here too, same as the "Add datasource" flow does.
…fy path - Use stdlib ipaddress for IP validation instead of colon heuristic - Catch all whitespace (tabs, newlines, NBSP) not just spaces - Split int parsing from port range validation (only port-named fields) - Validate union property variants recursively - Apply SKIP_TOP_LEVEL_KEYS only at top level, not nested - Run config field validation on "Verify connection" path - Update PR description to match actual name constraints - Add tests for all changes Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
|
@gasparian Addressed in 35eb85f — the "Save" path for existing datasources now runs |
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
…ant union fallback Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Summary
Datasource names with spaces and special characters were accepted in the form but caused errors after submission. This adds frontend validation so users get clear, immediate feedback.
Changes
Shared validation module
New
validate_datasource_name()function enforcing name rules:/): alphanumeric, hyphens, underscores, dotsAlso includes
validate_port()(1–65535 range) andvalidate_hostname()(RFC 952/1123 + IPv4/IPv6 via stdlibipaddress).Files
src/databao_cli/features/datasource/validation.pyUI validation
Validate name before add/verify actions; check required config fields, port ranges, hostname format, and union property variants. The "Verify connection" button now also runs config field validation before attempting verification.
Files
src/databao_cli/features/ui/components/datasource_manager.pysrc/databao_cli/features/ui/components/datasource_form.pyCLI validation
Validation loop in the interactive CLI workflow.
Files
src/databao_cli/workflows/datasource/add.pyTests
Unit tests covering the validation module and
validate_config_fields()(int vs port split, union properties, top-level key scoping, hostname-with-port rejection).Files
tests/test_datasource_validation.pytests/test_datasource_form_validation.pyTest Plan
make checkpassesmake testpasses (140 tests)