Fix AssertionError in _swap when constraints/indexes lack expected suffix#55
Merged
roed314 merged 1 commit intoroed314:masterfrom Feb 15, 2026
Merged
Conversation
…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
There was a problem hiding this comment.
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 oftarget_name()into the constraint/index rename loops, and guards them to avoid no-op renames that can rename the underlying relation unexpectedly.
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.
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