Fixes #595: SET CONSTRAINTS before poly column removal on revert#596
Fixes #595: SET CONSTRAINTS before poly column removal on revert#596bctiemann wants to merge 2 commits into
Conversation
remove_polymorphic_object_columns() dropped the content_type and object_id columns with ALTER TABLE but did not flush deferred FK trigger events first. On branch revert, the preceding row deletion queues deferred FK trigger events (from the DEFERRABLE INITIALLY DEFERRED through-table FK); the subsequent ALTER TABLE is then rejected by PostgreSQL with "pending trigger events". Mirror the fix already applied to _schema_remove_field for scalar fields: issue SET CONSTRAINTS ALL IMMEDIATE before the first ALTER TABLE. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
|
@claude /review and check only for correctness. |
|
Claude finished @bctiemann's task in 2m 29s —— View job Code Review — Correctness
The fix is correct. What the change does
The fix issues Correctness analysis
VerdictThe change is a minimal, targeted, correct fix. No issues found with correctness. |
arthanson
left a comment
There was a problem hiding this comment.
Should have a test for this scenario, should be easy to adapt from script in issue.
Adds ReferencedObjectDeletionTest.test_remove_poly_obj_columns_succeeds_with_pending_deferred_triggers to exercise the fix from commit 7ddc34a. The test reproduces the branching revert path: 1. Delete through-table rows (simulates Collector cascade). 2. Delete the COT instance via raw SQL → PostgreSQL queues a deferred trigger event on the referenced table (custom_objects_X). 3. Call remove_polymorphic_object_columns() — without the fix this fails with "cannot ALTER TABLE … because it has pending trigger events"; with the fix, SET CONSTRAINTS ALL IMMEDIATE fires and clears the pending event before the ALTER TABLE runs. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fixes: #595
Summary
remove_polymorphic_object_columns()dropped the_content_typeand_object_idcolumns withALTER TABLEbut did not flush deferred FK trigger events first.DEFERRABLE INITIALLY DEFERREDthrough-table FK (created by anyMULTIOBJECTfield on the same COT). PostgreSQL then rejects theALTER TABLEwithObjectInUse: cannot ALTER TABLE "custom_objects_<id>" because it has pending trigger events.SET CONSTRAINTS ALL IMMEDIATEbefore the firstALTER TABLE, mirroring what_schema_remove_field()already does for scalar fields.Test plan
🤖 Generated with Claude Code