-
-
Notifications
You must be signed in to change notification settings - Fork 10.1k
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
🐛 Fixed duplicate tags created when slugs contain spaces #14277
Merged
SimonBackx
merged 8 commits into
TryGhost:main
from
SimonBackx:fix/duplicate-tags-post-creation
Mar 10, 2022
Merged
🐛 Fixed duplicate tags created when slugs contain spaces #14277
SimonBackx
merged 8 commits into
TryGhost:main
from
SimonBackx:fix/duplicate-tags-post-creation
Mar 10, 2022
Conversation
This file contains 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
Codecov Report
@@ Coverage Diff @@
## main #14277 +/- ##
==========================================
- Coverage 55.48% 55.48% -0.01%
==========================================
Files 565 565
Lines 46840 46862 +22
Branches 3899 3898 -1
==========================================
+ Hits 25991 26003 +12
- Misses 20810 20820 +10
Partials 39 39
Continue to review full report at Codecov.
|
SimonBackx
force-pushed
the
fix/duplicate-tags-post-creation
branch
from
March 7, 2022 16:52
2d15657
to
6f35129
Compare
SimonBackx
force-pushed
the
fix/duplicate-tags-post-creation
branch
from
March 8, 2022 08:06
96c9cdb
to
3b9c439
Compare
matthanley
approved these changes
Mar 10, 2022
refs https://github.com/TryGhost/Team/issues/1284 When you create a new post with a tag that contains spaces, those spaces will get replaced by dashes. But instead of reusing an existing tag, a new tag is created.
refs https://github.com/TryGhost/Team/issues/1284 Matching tags by slug has been updated to work for slugs with spaces, but the fix causes a different complicated bug (test added and still failing).
refs https://github.com/TryGhost/Team/issues/1284 I was running into this difficult issue to solve: Say that we have an existing tag: `{slug: 'my-slug', name: 'This is my slug'}`. When you create a new post like this: `api.posts.add({title: 'test post', tags: [{slug: 'my slug'}]})` The current solution is to transform it into the following query in the onSaving event of `Post`: `api.posts.add({title: 'test post', tags: [{slug: 'my-slug'}]})` This works, but the only downside is that when creating a new tag, it creates it with the name 'my-slug' instead of 'my slug'. To work around this issue there needs to be a way for `bookshelf-relations` to have a different matching logic (to search for existing tags), separate from the insert logic (when creating new tags). Currently you cannot match existing tags on the slug `my-slug` (and not match on name `my slug` at the same time), while setting the name to `my slug` when inserting (but not when updating an existing tag) . As you understand, this gets far too complex for this small issue, since the user can just change the name afterwards.
SimonBackx
force-pushed
the
fix/duplicate-tags-post-creation
branch
from
March 10, 2022 11:50
3b9c439
to
b355b9d
Compare
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.
refs https://github.com/TryGhost/Team/issues/1284
id
(or foreign key) is set when creating or editing posts.skipDuplicateChecks
option togenerateSlug
model plugin.Edge case
Say that we have an existing tag:
{slug: 'my-slug', name: 'This is my slug'}
When you create a new post like this:
api.posts.add({title: 'test post', tags: [{slug: 'my slug'}]})
The current solution is to transform it into the following query in the
onSaving
event of Post:api.posts.add({title: 'test post', tags: [{slug: 'my-slug'}]})
This works! But the only downside is, that when creating a new tag, it creates it with the name 'my-slug' instead of 'my slug'.
To work around this issue there needs to be a way for
bookshelf-relations
to have a different matching logic (to search for existing tags), separate from the insert logic (when creating new tags). Currently you cannot match existing tags on the slugmy-slug
(and not match on namemy slug
at the same time), while setting the name tomy slug
when inserting (but not when updating an existing tag). This gets far too complex for this small issue, since the user can just change the name afterwards.