question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

django-taggit creating dozens of queries in admin panel when saving custom tag

See original GitHub issue

I posted about this on StackOverlow, but here it is in summary:

I have a GenericTaggedItemBase for my tagging through model so I can add an extra field to tags (a twitter username). I have a post_save hook which is supposed to check for tags added to content which have twitter usernames, and to post a tweet to those usernames with a link to the content.

When I save the content item and look in the Django Debug Toolbar I see it make some queries I’ve written in the post_save hook, but then some weirdness like this:

SELECT * FROM tag_mappings LIMIT 21

The following queries after that basically loop through the 21 results from the first query and looks up the tags.

There are more code samples on the StackOverflow question but this looks to be something django-taggit is doing. Here’s a full screeshot:

image

Is this a known issue? I’m not sure if it happens without the custom through model or the post_save hook; happy to check.

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:11 (7 by maintainers)

github_iconTop GitHub Comments

1reaction
rtpgcommented, Apr 14, 2021

thanks for piping in! Alright, I’m going to close this one out, and assume that was the case here. Only have so many hours in the day, and triaging 100+ issues took a while 😃

1reaction
mattandrewscommented, Apr 14, 2021

This is an ancient issue of mine, but in retrospect I’m fairly sure it was something weird on my end rather than django-taggit. I was doing all kinds of non-Django things because I was new to the framework (eg. running raw SQL queries as you can see in the linked StackOverflow post) via post-save hooks.

Read more comments on GitHub >

github_iconTop Results From Across the Web

django-taggit creating dozens of queries in admin panel when ...
I have a GenericTaggedItemBase for my tagging through model so I can add an extra field to tags (a twitter username). I have...
Read more >
Using tags in the admin — django-taggit 1.3.0 documentation
If you want to show tags in ModelAdmin.list_display , you can add a custom display method to the ModelAdmin , using prefetch_related() to...
Read more >
django-taggit: Is there a way to produce less db queries?
When I iterate over Entry.objects.all() in a template, entry.tags.all produces one more query to the database. Is it possible to reduce queries number?...
Read more >
django-taggit - Read the Docs
Customizing taggit. 7.1 Using a Custom Tag or Through Model. By default django-taggit uses a “through model” with a GenericForeignKey on it, ...
Read more >
Django-Taggit - Adding Tags to Django Models - YouTube
This video will dive into the django - taggit library, which is used to add tags to Django models. Tagging is a common...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found