fix 2 issues regarding connection#94
Merged
bmichele merged 6 commits intoJul 7, 2026
Merged
Conversation
…oduct The foreign-key introspection query joined information_schema constraint_column_usage to key_column_usage on constraint_name alone, producing a Cartesian product for composite FKs (N columns → N² rows) and phantom cross-matches for same-named constraints on different tables. Added AND ccu.ordinal_position = kcu.ordinal_position to the join condition so columns pair correctly by position within the constraint. Also added tests for composite FKs and duplicate constraint names.
There was a problem hiding this comment.
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 362e5c0060
ℹ️ About Codex in GitHub
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT, Codex can also answer questions or update the PR, like "@codex address that feedback".
Catch psycopg.Error at psycopg.connect() and re-raise with a sanitized message so the connection string (including password) never appears in CLI output, CI logs, or shell history. The existing _redact_db_url() only covered the happy-path status message; libpq's DSN parser echoes the full connection string in its error for malformed DSNs, leaking passwords. Tests: update test_password_not_in_exception to patch psycopg.connect (where the real leak occurs) with a libpq-style error containing the password, and assert it is not present in the re-raised exception.
- Rewrite FK query to use pg_constraint directly instead of information_schema.constraint_column_usage (which lacks ordinal_position in PostgreSQL). The new query pairs referencing columns (conkey) with referenced columns (confkey) via generate_subscripts for correct composite-FK support. - Add --db-url pytest CLI option and pg_conn fixture so live tests can connect to a real database. Tests marked @pytest.mark.db are skipped when --db-url is not provided. - Add TestLivePostgresLive with 5 live tests: - test_empty_db_returns_empty_index - test_single_table_basic (columns, PK, index) - test_foreign_keys_live (single-column FK) - test_composite_foreign_key_live (multi-column FK pairing) - test_multi_schema_no_collision_live (same table name in different schemas) - Register 'db' marker in pyproject.toml so tests are properly deselected by default.
bmichele
requested changes
Jul 6, 2026
bmichele
left a comment
Contributor
There was a problem hiding this comment.
Thank you for fixing those issues! 💪
Before merging:
- I think we should avoid having a detailed docs/guides/testing.md. No one is going to read it anyway. Instead, add a short reference in CONTRIBUTING.md
- fix linting/formatting issues (see current CONTRIBUTING.md)
I can them merge the PR 😃
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
Fixes the PostgreSQL foreign-key introspection query in
postgres_live.pywhich had two compounding bugs:Cartesian product on composite FKs — the
information_schemajoin onconstraint_namealone produced N² rows for N-column FKs, causing phantom cross-matches and incorrect column pairings.constraint_column_usagelacksordinal_position— this information_schema view doesn't expose the column position, so even with an ordinal_position guard the join was unreliable across PostgreSQL versions.How it's fixed: The FK query now queries
pg_constraintdirectly, pairing referencing columns (conkey) with referenced columns (confkey) viagenerate_subscripts— a version-stable approach that correctly handles single-column and composite FKs alike.Alongside the fix, live integration tests were added so this behavior can be validated against a real database, and error messages from
introspect_db()now redact passwords.Commit history
362e5c0d946622ce445ebTest Plan
uv run pytest tests/test_schema_parsers/test_postgres_live.py— all 18 mocked tests pass (single FK, views, multi-schema, composite FK, duplicate constraint names).uv run pytest tests/ -m db --db-url "postgresql://user:pass@localhost/db" -v— 5 live tests create their own tables, verify FK pairing (single + composite), multi-schema isolation, and run clean teardown. Skipped automatically without--db-url.uv run pytest tests/— 428 passed, 1 skipped.Checklist
uv run ruff check && uv run pytest)