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
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions tagging/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ def _get_usage(self, model, counts=False, min_count=None,
if min_count is not None:
counts = True

params = params or []
model_table = qn(model._meta.db_table)
model_pk = '%s.%s' % (model_table, qn(model._meta.pk.column))
query = """
Expand Down Expand Up @@ -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

extra_joins = ' '.join(compiler.get_from_clause()[0][1:])

if where:
if len(queryset.query.where):
where, params = compiler.compile(queryset.query.where)
extra_criteria = 'AND %s' % where
else:
extra_criteria = ''
Expand Down