fix: DSN format handling, ambiguous URL detection, docs#278
Closed
cmeans-claude-dev[bot] wants to merge 7 commits intomainfrom
Closed
fix: DSN format handling, ambiguous URL detection, docs#278cmeans-claude-dev[bot] wants to merge 7 commits intomainfrom
cmeans-claude-dev[bot] wants to merge 7 commits intomainfrom
Conversation
…_URL Production uses DSN format (host=X dbname=Y user=Z password=W) for psycopg. Alembic needs a SQLAlchemy URL. Auto-convert DSN to URL format when the value doesn't start with postgresql://. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Extract dsn_to_sqlalchemy_url() into helpers.py with proper handling of single-quoted DSN values, URL-encoding of special characters in user/password, and postgresql:// dialect normalization. Replace the fragile inline regex in alembic/env.py. Fix deploy.sh passing unsupported positional args to mcp-awareness-migrate. 10 new tests. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
F1: Replace hand-rolled regex with psycopg.conninfo.conninfo_to_dict()
for battle-tested DSN parsing. Extra params (sslmode, connect_timeout)
forwarded as URL query string parameters.
F2: Raise ValueError on empty/whitespace input instead of silently
producing defaults.
F3: Unix socket paths placed in query string, not netloc.
F4: Fix README documenting broken `mcp-awareness-migrate upgrade head`.
F6: Strengthen test_whitespace_stripped to assert full URL.
F7: Remove self-referential PR refs from CHANGELOG.
864 tests (was 858).
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
The `if not raw` check after conninfo_to_dict is unreachable: empty input is caught before the call, and non-empty garbage raises ProgrammingError from psycopg. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…eError Docstring claimed ValueError on unparseable input, but psycopg's conninfo_to_dict raises ProgrammingError. Align docs with behavior. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
…sparsing URL passthrough now validates that the netloc doesn't contain multiple @ signs (which indicates an unencoded @ in the password). Raises ValueError with guidance to percent-encode as %40 or use DSN format. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Shell splits unquoted DSN values on spaces, silently dropping password/user/dbname. Document that DSN format values must be quoted in env files across README, data dictionary, migrate.py error message, and alembic/env.py error message. Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Contributor
Author
|
Superseded by new PR from clean branch (old branch had squash-merge conflicts) |
cmeans-claude-dev bot
added a commit
that referenced
this pull request
Apr 13, 2026
## Summary Post-#276 follow-up. Addresses QA findings and a production deploy issue: - **Ambiguous URL detection** — `dsn_to_sqlalchemy_url()` now detects unencoded `@` in URL passwords (e.g., `postgresql://u:p@ss@h:5432/db`) and raises `ValueError` instead of silently misparsing - **Docstring fix** — correct exception types documented on `dsn_to_sqlalchemy_url()` - **DSN quoting docs** — document that DSN format values must be quoted in env files to prevent shell space-splitting (discovered during production deploy) - **README** — fix `mcp-awareness-migrate upgrade head` syntax Supersedes #278 (rebased to clean branch after squash-merge conflicts). ## QA ### Prerequisites - `pip install -e ".[dev]"` ### Manual tests 1. - [x] **Ambiguous URL raises** — `dsn_to_sqlalchemy_url("postgresql://u:p@ss@h:5432/db")` raises `ValueError` 2. - [x] **README env table** — `AWARENESS_DATABASE_URL` documents both URL and DSN formats with quoting note 3. - [x] **`mcp-awareness-migrate` error** — run without env var, shows both formats 4. - [x] **README upgrade section** — says `mcp-awareness-migrate` (no positional args) --------- Co-authored-by: cmeans-claude-dev[bot] <3223881+cmeans-claude-dev[bot]@users.noreply.github.com> Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Follow-up to #276 (squash-merged). Addresses QA findings from #276 that landed after the squash merge, plus a production deploy issue:
@in URL passwords — raisesValueErrorinstead of silently misparsing (postgresql://u:p@ss@hwould connect to wrong host)dsn_to_sqlalchemy_url()migrate.pyandalembic/env.pyerror messagesQA
Prerequisites
pip install -e ".[dev]"Manual tests (via MCP tools)
dsn_to_sqlalchemy_url("postgresql://u:p@ss@h:5432/db")in a Python shell. Expected:ValueErrormentioning unencoded@dsn_to_sqlalchemy_url("postgresql+psycopg://u:p%40ss@h:5432/db"). Expected: returns the URL unchangedAWARENESS_DATABASE_URLrow documents both URL and DSN formats with quoting notemcp-awareness-migrateerror — run withoutAWARENESS_DATABASE_URLset, verify error shows both URL and DSN examples with quoting note🤖 Generated with Claude Code