Skip to content

Conversation

@timb07
Copy link
Contributor

@timb07 timb07 commented Sep 4, 2025

Prior to this change, if Psycopack was used on a table with a deferrable unique constraint, then after the swap sync_schemas stage, any updates to the original table would cause the trigger that updates the psycopack table to fail with this error:

    ON CONFLICT does not support deferrable unique constraints/exclusion constraints as arbiters

That error results from the use of ON CONFLICT DO NOTHING in the copy function used by the trigger.

This change removes test coverage of deferrable unique constraints and adds a check to the pre_validate stage to reject a table that has a deferrable unique constraint.

(This issue was discovered while working on tests to reproduce the bug in #49.)

@github-actions
Copy link

github-actions bot commented Sep 4, 2025

Coverage Report Results

Name Stmts Miss Branch BrPart Cover
src/psycopack/__init__.py 6 0 0 0 100%
src/psycopack/_commands.py 112 0 6 0 100%
src/psycopack/_conn.py 5 0 0 0 100%
src/psycopack/_const.py 3 0 0 0 100%
src/psycopack/_cur.py 24 0 2 0 100%
src/psycopack/_identifiers.py 12 0 2 0 100%
src/psycopack/_introspect.py 167 0 16 0 100%
src/psycopack/_logging.py 2 0 0 0 100%
src/psycopack/_psycopg.py 5 0 0 0 100%
src/psycopack/_registry.py 58 0 6 0 100%
src/psycopack/_repack.py 362 0 122 0 100%
src/psycopack/_tracker.py 165 0 36 0 100%
tests/conftest.py 19 0 0 0 100%
tests/factories.py 38 0 8 0 100%
tests/test_cur.py 20 0 2 0 100%
tests/test_fixtures.py 5 0 0 0 100%
tests/test_package.py 3 0 0 0 100%
tests/test_repack.py 750 0 4 0 100%
TOTAL 1756 0 204 0 100%

1 empty file skipped.

@timb07 timb07 force-pushed the disallow-deferrable-unique-constraint branch from f0d2e81 to 617b899 Compare September 4, 2025 02:09
Copy link

@flpcury flpcury left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@timb07 timb07 force-pushed the disallow-deferrable-unique-constraint branch 2 times, most recently from a589f56 to 3d22d07 Compare September 4, 2025 06:41
Copy link
Collaborator

@marcelofern marcelofern left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A good amount of clarification in this Postgres mailing list thread

Prior to this change, if Psycopack was used on a table with a deferrable
unique constraint, then after the "sync_schemas" stage, any updates to the original
table would cause the trigger that updates the psycopack table to fail with
this error:
    ON CONFLICT does not support deferrable unique constraints/exclusion
     constraints as arbiters

That error results from the use of "ON CONFLICT DO NOTHING" in the copy
function used by the trigger.

This change removes test coverage of deferrable unique constraints and adds
a check to the pre_validate stage to reject a table that has a deferrable
unique constraint.
@timb07 timb07 force-pushed the disallow-deferrable-unique-constraint branch from 3d22d07 to f7314da Compare September 9, 2025 03:39
@timb07 timb07 requested a review from a team as a code owner September 9, 2025 03:39
@timb07 timb07 merged commit c92adab into main Sep 9, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants