Skip to content

Fix tag duplication when saving posts#496

Merged
compscidr merged 2 commits intomainfrom
fix/tag-duplication
Mar 16, 2026
Merged

Fix tag duplication when saving posts#496
compscidr merged 2 commits intomainfrom
fix/tag-duplication

Conversation

@compscidr
Copy link
Collaborator

Summary

  • Replace Association("Tags").Clear() + struct-based Updates() with Association("Tags").Replace() to atomically swap tag associations without duplication
  • Remove Tags from the struct passed to Updates() so GORM doesn't re-insert them
  • Add missing Tag migration to admin test setup
  • Add test that saves a post with tags twice and verifies the count stays at 2

Closes #487

Test plan

  • Existing tests pass
  • New test verifies tags don't double on repeated saves
  • Manual: edit a post with tags, save multiple times, confirm tag count stays stable

🤖 Generated with Claude Code

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>
Copilot AI review requested due to automatic review settings March 16, 2026 17:34
@codecov
Copy link

codecov bot commented Mar 16, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 45.65%. Comparing base (ef0a4cd) to head (a68fc44).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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 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-based Updates() to Association("Tags").Replace() to avoid duplicating associations.
  • Avoid passing Tags via struct Updates() 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>
@compscidr compscidr merged commit 19a393b into main Mar 16, 2026
2 checks passed
@compscidr compscidr deleted the fix/tag-duplication branch March 16, 2026 17:57
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.

saving tags results in double the tags each time

2 participants