Merged
Conversation
Use Association("Tags").Replace() instead of Clear() followed by
struct-based Updates() which caused GORM to re-insert the associations.
Also add Tag migration to admin tests and a test that verifies tags
don't double on repeated saves.
Closes #487
Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #496 +/- ##
==========================================
- Coverage 45.68% 45.65% -0.03%
==========================================
Files 8 8
Lines 2038 2037 -1
==========================================
- Hits 931 930 -1
Misses 990 990
Partials 117 117 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Pull request overview
Fixes tag duplication when repeatedly saving posts by changing how GORM tag associations are updated, and adds regression coverage in admin tests (Issue #487).
Changes:
- Switch post tag updates from
Association("Tags").Clear()+ struct-basedUpdates()toAssociation("Tags").Replace()to avoid duplicating associations. - Avoid passing
Tagsvia structUpdates()so GORM doesn’t re-insert associations. - Update admin test DB migrations and add a regression test to ensure tag count remains stable across repeated saves.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
admin/admin.go |
Updates tag persistence logic in UpdatePost to use association replacement. |
admin/admin_test.go |
Adds Tag migration to test setup and a regression test for repeated tag saves. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Wrap Updates + tag Replace + draft/post_type updates in a DB transaction with error handling, returning 500 on failure - Preload Tags (alongside PostType) before returning JSON so the response includes the updated tags - Check json.Unmarshal error in test for better diagnostics Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
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.
Summary
Association("Tags").Clear()+ struct-basedUpdates()withAssociation("Tags").Replace()to atomically swap tag associations without duplicationTagsfrom the struct passed toUpdates()so GORM doesn't re-insert themTagmigration to admin test setupCloses #487
Test plan
🤖 Generated with Claude Code