Skip to content

fix: DSN format handling, ambiguous URL detection, docs#278

Closed
cmeans-claude-dev[bot] wants to merge 7 commits intomainfrom
fix/alembic-dsn-format
Closed

fix: DSN format handling, ambiguous URL detection, docs#278
cmeans-claude-dev[bot] wants to merge 7 commits intomainfrom
fix/alembic-dsn-format

Conversation

@cmeans-claude-dev
Copy link
Copy Markdown
Contributor

@cmeans-claude-dev cmeans-claude-dev bot commented Apr 13, 2026

Summary

Follow-up to #276 (squash-merged). Addresses QA findings from #276 that landed after the squash merge, plus a production deploy issue:

  • F5 fix: Detect ambiguous @ in URL passwords — raises ValueError instead of silently misparsing (postgresql://u:p@ss@h would connect to wrong host)
  • Docstring fix: Correct exception types documented on dsn_to_sqlalchemy_url()
  • DSN quoting docs: During production deploy, unquoted DSN in env file caused shell space-splitting — password silently dropped. Document the quoting requirement in README, data dictionary, migrate.py and alembic/env.py error messages

QA

Prerequisites

  • pip install -e ".[dev]"

Manual tests (via MCP tools)

    • Ambiguous URL raises — call dsn_to_sqlalchemy_url("postgresql://u:p@ss@h:5432/db") in a Python shell. Expected: ValueError mentioning unencoded @
    • Encoded @ passes through — call dsn_to_sqlalchemy_url("postgresql+psycopg://u:p%40ss@h:5432/db"). Expected: returns the URL unchanged
    • README env table — verify AWARENESS_DATABASE_URL row documents both URL and DSN formats with quoting note
    • Data dictionary — verify connection string entry documents quoting requirement
    • mcp-awareness-migrate error — run without AWARENESS_DATABASE_URL set, verify error shows both URL and DSN examples with quoting note

🤖 Generated with Claude Code

cmeans-claude-dev[bot] and others added 7 commits April 12, 2026 21:37
…_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>
@cmeans-claude-dev cmeans-claude-dev bot added Dev Active Developer is actively working on this PR; QA should not start Awaiting CI Dev complete, waiting for CI/Codecov to pass before QA and removed Dev Active Developer is actively working on this PR; QA should not start labels Apr 13, 2026
@cmeans-claude-dev cmeans-claude-dev bot changed the title docs: document DSN quoting requirement for env files fix: DSN format handling, ambiguous URL detection, docs Apr 13, 2026
@cmeans-claude-dev
Copy link
Copy Markdown
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Awaiting CI Dev complete, waiting for CI/Codecov to pass before QA

Projects

None yet

Development

Successfully merging this pull request may close these issues.

0 participants