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

Prevent exception when query object has empty WHERE clause #2

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from

Conversation

mrmikardo
Copy link

Hi there 👋

I discovered your fork of the django-tagging project from the discussion on this PR. I'm trying to use this in a project which runs on Django 4, and made some small fixes which I've included in this PR.

This PR modifies the get_usage_for_queryset() method to handle empty WHERE-clauses in the passed-in query.

Let me know if you'd like any additional info!

mrmikardo and others added 3 commits June 17, 2024 13:11
Don't attempt to destructure a return value which could be None.
…hod-187082048

[#187082048] Fix model manager method
@@ -177,10 +178,11 @@ def usage_for_queryset(self, queryset, counts=False, min_count=None):
Passing a value for ``min_count`` implies ``counts=True``.
"""
compiler = queryset.query.get_compiler(using=queryset.db)
where, params = compiler.compile(queryset.query.where)
params = None
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this line can be removed - does params really need to be set to None here?

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

params needs to be at least declared here, otherwise it will not be available in the return statement of this function. Results in local variable 'params' referenced before assignment

@frankystone
Copy link

I ran into a FullResultSet Exception when using tags_for_model [model] as all_tags. With this change all runs fine.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants