Skip to content

Commit

Permalink
fix isnull lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
timgraham committed May 6, 2024
1 parent b6efa04 commit 69e5f46
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ jobs:
defer_regress
from_db_value
lookup.tests.LookupTests.test_escaping
lookup.tests.LookupTests.test_isnull_textfield
lookup.tests.LookupQueryingTests.test_isnull_lookup_in_filter
model_fields
or_lookups
sessions_tests
Expand Down
16 changes: 3 additions & 13 deletions django_mongodb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -273,16 +273,6 @@ def _decode_child(self, child):

lookup_type = child.lookup_name

# Since NoSql databases generally don't support aggregation or
# annotation, pass true unless the query has a get_aggregation() method.
# It's a little troubling however that the _nomalize_lookup_value
# method seems to only use this value in the case that the value is an
# iterable and the lookup_type equals isnull.
annotation = (
self.get_aggregation(using=self.connection)[None]
if hasattr(self, "get_aggregation")
else True
)
value = rhs_params
packed = child.lhs.get_group_by_cols()[0]
alias = packed.alias
Expand All @@ -303,11 +293,11 @@ def _decode_child(self, child):

field = next(f for f in opts.fields if f.column == column)

value = self._normalize_lookup_value(lookup_type, value, field, annotation)
value = self._normalize_lookup_value(lookup_type, value, field)

return field, lookup_type, value

def _normalize_lookup_value(self, lookup_type, value, field, annotation):
def _normalize_lookup_value(self, lookup_type, value, field):
"""
Undo preparations done by lookups not suitable for MongoDB, and pass
the lookup argument through DatabaseOperations.prep_lookup_value().
Expand All @@ -320,7 +310,7 @@ def _normalize_lookup_value(self, lookup_type, value, field, annotation):
"not to be a list. Only 'in'-filters can be used with "
"lists." % lookup_type
)
value = annotation if lookup_type == "isnull" else value[0]
value = value[0]

# Remove percent signs added by PatternLookup.process_rhs() for LIKE
# queries.
Expand Down

0 comments on commit 69e5f46

Please sign in to comment.