-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Fix issue when reordering tags and @@remove_unused_tags is true #1154
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Fix issue when reordering tags and @@remove_unused_tags is true #1154
Conversation
f360c13 to
737b75f
Compare
8cafe4a to
87e4a35
Compare
|
Can you rebase on master ? i'm hesitant to merge it as people using pgbouncer, could have transaction disabled. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes an issue where reordering tags fails when remove_unused_tags is enabled. The fix ensures that tag deletion and creation operations happen atomically within a transaction, and that the after_destroy callback is changed to after_destroy_commit to prevent premature tag cleanup.
- Changed
after_destroytoafter_destroy_commitin the Tagging model to delay tag cleanup until transaction commits - Wrapped tag destroy/create operations in a transaction to ensure atomicity
- Added test coverage for reordering tags with
remove_unused_tagsenabled
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| lib/acts-as-taggable-on/tagging.rb | Changed callback from after_destroy to after_destroy_commit to prevent tags from being removed before transaction commits |
| lib/acts-as-taggable-on/taggable/core.rb | Wrapped tag destruction and creation in a transaction block for atomicity |
| spec/acts_as_taggable_on/taggable_spec.rb | Added test case to verify tags can be reordered when remove_unused_tags is enabled |
| CHANGELOG.md | Added entry documenting the bug fix |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| expect(ids).to eq(ids.sort) | ||
| end | ||
|
|
||
| it 'can reorder tags successfully when @@remove_unused_tags is true' do |
Copilot
AI
Oct 31, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment incorrectly uses @@remove_unused_tags (class variable notation) when it should reference the configuration setting remove_unused_tags. The double @@ is misleading as this is an ActsAsTaggableOn configuration attribute, not a class variable.
| it 'can reorder tags successfully when @@remove_unused_tags is true' do | |
| it 'can reorder tags successfully when remove_unused_tags is true' do |
When reordering taggings, the taggings get deleted and recreated. However, by the time the taggings are recreated, the tags have already been removed. Fixed by wrapping the delete + create in a transaction, and only removing unused tags on transaction commit.
87e4a35 to
35b68f4
Compare
|
@seuros I've rebased. I guess a fix that didn't rely on transactions would involve creating the new taggings before destroying the old taggings. I could put up a separate PR for that? |
|
Active Record allow you to check if the connection support transactions. Can you check if the versions are raising or just ignoring it. PS: if only 7.2 is problematic, we can drop support. But if they all raise , we will need to find a proper solution. PGbouncer disable transaction by default if i recall correctly. |
Fixes #946
When reordering taggings, the taggings get deleted and recreated. However, by the time the taggings are recreated, the tags have already been removed.
Fixed by wrapping the delete + create in a transaction, and only removing unused tags on transaction commit.