Skip to content

Fix AssertionError in _swap when constraints/indexes lack expected suffix#55

Merged
roed314 merged 1 commit intoroed314:masterfrom
edgarcosta:fix-swap-assertion-error
Feb 15, 2026
Merged

Fix AssertionError in _swap when constraints/indexes lack expected suffix#55
roed314 merged 1 commit intoroed314:masterfrom
edgarcosta:fix-swap-assertion-error

Conversation

@edgarcosta
Copy link
Collaborator

When a constraint or index on a _tmp table doesn't have the _tmp suffix, target_name() would hit an assertion failure because original_name was never stripped but the assert still expected original_name + source == name.

Restructure target_name() so it only strips and asserts when the name actually ends with the source suffix, and logs a warning otherwise.

Also move _rename_if_exists out of target_name() into the caller loops, guarded by a check that the target name differs from the current name. This prevents a no-op rename from accidentally renaming the constraint itself (via _rename_if_exists finding it in pg_class) and then failing the subsequent ALTER TABLE RENAME.

Fixes #53

…ffix

When a constraint or index on a _tmp table doesn't have the _tmp suffix,
target_name() would hit an assertion failure because original_name was
never stripped but the assert still expected original_name + source == name.

Restructure target_name() so it only strips and asserts when the name
actually ends with the source suffix, and logs a warning otherwise.

Also move _rename_if_exists out of target_name() into the caller loops,
guarded by a check that the target name differs from the current name.
This prevents a no-op rename from accidentally renaming the constraint
itself (via _rename_if_exists finding it in pg_class) and then failing
the subsequent ALTER TABLE RENAME.

Fixes roed314#53
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Fixes an AssertionError during table swaps (_swap) when constraints or indexes on _tmp tables don’t include the expected _tmp suffix, improving robustness of reload/update workflows in psycodict.

Changes:

  • Updates _swap.target_name() to only strip/assert the source suffix when the name actually ends with that suffix; otherwise logs a warning.
  • Moves _rename_if_exists() calls out of target_name() into the constraint/index rename loops, and guards them to avoid no-op renames that can rename the underlying relation unexpectedly.

@roed314 roed314 merged commit d3af8ae into roed314:master Feb 15, 2026
6 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.

issue with update_from_file

2 participants