Skip to content
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

Bulk adding tags can create "duplicate" posts_tags rows #21414

Open
1 task done
brvnnghi opened this issue Oct 25, 2024 · 1 comment
Open
1 task done

Bulk adding tags can create "duplicate" posts_tags rows #21414

brvnnghi opened this issue Oct 25, 2024 · 1 comment
Labels

Comments

@brvnnghi
Copy link

Issue Summary

Tag count doubled when adding an existing tag in a post again via Context Menu.

The correct behaviour would be, if a tag is already existed in a post, it should not be tagged again using "Add a Tag" in Context Menu.

img 2
img 3
img 4

Steps to Reproduce

  1. Create new tag
  2. Tag inside a post
  3. Tag again using Context Menu ("Add a tag")
  4. See tag count = 2 when there's only 1 post

Ghost Version

5.94

Node.js Version

22

How did you install Ghost?

Linux / Local

Database type

MySQL 8

Browser & OS version

No response

Relevant log / error output

No response

Code of Conduct

  • I agree to be friendly and polite to people in this repository
@github-actions github-actions bot added the needs:triage [triage] this needs to be triaged by the Ghost team label Oct 25, 2024
Copy link
Member

kevinansfield commented Oct 28, 2024

Thank you for the report.

The problem code is located here. PRs are welcome 🙂

Aside from the double counting the duplicate post_id+tag_id rows in the posts_tags table does not appear to cause any other issues. Deleting the attached tag from the UI correctly deletes both rows.

If you're aware of any other problems this causes please elaborate.

As for the fix there are two approaches:

  1. Add a check to the bulk edit feature to skip inserting duplicate rows
  2. Add a unique index across the posts_tags.{post_id,tag_id} columns so data integrity is ensured at the database level (this will likely also require approach 1 or a similar handling of errors during the insert, as well as a migration to remove duplicates before the unique index is added)

@kevinansfield kevinansfield added bug [triage] something behaving unexpectedly P4 - Low labels Oct 28, 2024 — with Linear
@github-actions github-actions bot removed the needs:triage [triage] this needs to be triaged by the Ghost team label Oct 28, 2024
@kevinansfield kevinansfield changed the title Double Tag count when adding existing tag via Context Menu Bulk adding tags can create "duplicate" post_tags rows Oct 28, 2024
@kevinansfield kevinansfield changed the title Bulk adding tags can create "duplicate" post_tags rows Bulk adding tags can create "duplicate" posts_tags rows Oct 28, 2024
@kevinansfield kevinansfield removed the bug [triage] something behaving unexpectedly label Oct 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants