get() returned more than one Tag -- it returned 2!
See original GitHub issueHello Sometimes when adding tags to an existing object, I am getting the following error.
get() returned more than one Tag -- it returned 2!
Here is the code I am using
...
publication.tags.set(all_tags, clear=True)
publication.save()
# I also tried
publication.tags.set(all_tags)
publication.save()
# and
publication.tags.add(*all_tags)
publication.save()
# but still getting the same issue
...
Notes:
- I am not using any get function
- Django version 4.1
Issue Analytics
- State:
- Created a year ago
- Comments:5 (3 by maintainers)
Top Results From Across the Web
django - get() returned more than one topic - Stack Overflow
get() returned more than one topic -- it returned 2! The above error indicatess that you have more than one record in the...
Read more >get() returned more than one Answer -- it returned 2!
Saw one traceback where it looks like we do a .get() for a flow_id that returns two records. Needs investigation. Traceback: Internal Server...
Read more >MultipleObjectsReturned: get() returned more than one ...
MultipleObjectsReturned: get() returned more than one EmailAddress -- it returned 2! Hi,. We've encountered the error in Postorius on ...
Read more >get() returned more than one Post -- it returned 2! : r/django
i was trying to make like button for my blog but i'm getting that error get() returned more than one Post -- it...
Read more >MultipleObjectsReturned: get() returned more than one Question
Now you may perform more filters like Model.objects.filter(fname=first_name).first() if you want only first.
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
@naskio thank you very much for that detail! It sounds very important.
If in your system you have that problem, the easiest thing to do would be to normalize manually in a database migration. So for example you find all of the
TaggedItem
s that are pointing toUKRAINE
and then point them toUkraine
. From there, you should be able to deleteUKRAINE
.You’ll need to do some database cleanup. I think though that this error should have its own handling, though. And it might even make sense for us to write a helper management command… but at the very least we should document what to do.
@rtpg For me the ideal solution would be to have both options: 1- Handling this case by taking only the first tag when get() returns more than one, This would be more flexible enabling us to disable
TAGGIT_CASE_INSENSITIVE
again without impacting the data. 2- A management command if someone decides to enableTAGGIT_CASE_INSENSITIVE
and keep only one instance of similar tags.