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 7, 2024
1 parent 09da727 commit 28f52b1
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .github/workflows/test-python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,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
18 changes: 3 additions & 15 deletions django_mongodb/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -266,19 +266,7 @@ def _decode_child(self, child):
raise NotSupportedError("Pattern lookups on UUIDField are not supported.")

rhs, rhs_params = child.process_rhs(self.compiler, self.connection)

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 @@ -299,11 +287,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 @@ -316,7 +304,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 28f52b1

Please sign in to comment.