Opened 8 years ago

Closed 7 years ago

#5079 closed defect (fixed)

Duplicate key error when tagging media "tag" and "#tag"

Reported by: ayleph Owned by:
Priority: major Milestone: 0.9.0
Component: programming Keywords: tags
Cc: Parent Tickets:


I have a user who was getting server errors when uploading media. He was tagging his upload as "tag,#tag". "tag", "#tag", "Tag", and possibly other permutations are given the same tag number in my postgresql database.

mediagoblin-prod=# select distinct tag from core__media_tags where name='tag';
(1 row)

mediagoblin-prod=# select distinct tag from core__media_tags where name='#tag';
(1 row)

mediagoblin-prod=# select distinct tag from core__media_tags where name='Tag';
(1 row)

This causes a foreign key constraint violation when attempting to add "#tag" to core__media_tags.

Error - <class 'sqlalchemy.exc.IntegrityError'>: (IntegrityError) duplicate key value violates unique constraint "core__media_tags_tag_media_entry_key"
DETAIL:  Key (tag, media_entry)=(337, 3534) already exists.
 'INSERT INTO core__media_tags (media_entry, tag, name) VALUES (%(media_entry)s, %(tag)s, %(name)s) RETURNING' {'tag': 337, 'name': u'#tag', 'media_entry': 3534}

I can reproduce this error by uploading by own media tagged as "tag,#tag". Interestingly, if I tag the media as "tag,tag" then I do not get the foreign key constraint violation. If we can ignore duplicate identical tags in the upload (tag, tag), then I think it would be good if we could also ignore tags which result in duplicate tag numbers in the table.

breton suggested I tag with under the 0.8.0 milestone.

Attachments (1)

0001-Fix-5079-tags-unicity-is-on-the-slug-not-the-name.patch (2.7 KB ) - added by Loic Dachary 7 years ago.

Download all attachments as: .zip

Change History (7)

comment:1 by Boris Bobrov, 8 years ago

Keywords: tags added; tag foreign_key constraint violation core__media_tags removed
Owner: set to Boris Bobrov
Status: newin_progress

thanks for the report.

Note to self: this seems to be because of db/ +734 -- tags are matched based on slug. Check from there.

comment:2 by Christopher Allan Webber, 8 years ago


I don't think this is 0.8.0 critical but if it happens by then I'd be happy to merge it.

comment:3 by Loic Dachary, 7 years ago

Owner: Boris Bobrov removed
Status: in_progressreview

comment:4 by ayleph, 7 years ago

Thanks for the patch loic! I'll test locally and update with results.

comment:5 by ayleph, 7 years ago

Patch applies successfully and appears to fix the issue. Without patch, setting tags = "tag, #tag, Tag" results in server error. With patch, settings tags = "tag, #tag, Tag" results in media being added with "Tag" as tag. Fine by me, as "tag", "#tag", and "Tag" all end up in the same collection.

Good to push to master in my opinion.

comment:6 by ayleph, 7 years ago

Resolution: fixed
Status: reviewclosed

Applied as of 679f729. Thanks for the patch.

Note: See TracTickets for help on using tickets.