diff --git a/ormar/queryset/actions/filter_action.py b/ormar/queryset/actions/filter_action.py index cbb1745..b013cd3 100644 --- a/ormar/queryset/actions/filter_action.py +++ b/ormar/queryset/actions/filter_action.py @@ -141,8 +141,10 @@ class FilterAction(QueryAction): op_attr = FILTER_OPERATORS[self.operator] if self.operator == "isnull": op_attr = "is_" if self.filter_value else "isnot" - self.filter_value = None - clause = getattr(self.column, op_attr)(self.filter_value) + filter_value = None + else: + filter_value = self.filter_value + clause = getattr(self.column, op_attr)(filter_value) clause = self._compile_clause( clause, modifiers={"escape": "\\" if self.has_escaped_character else None}, ) diff --git a/tests/test_queries/test_isnull_filter.py b/tests/test_queries/test_isnull_filter.py index 2db0c9f..1b9a7a1 100644 --- a/tests/test_queries/test_isnull_filter.py +++ b/tests/test_queries/test_isnull_filter.py @@ -68,6 +68,13 @@ async def test_is_null(): assert tolkien.books[0].year is None assert tolkien.books[0].title == "The Hobbit" + tolkien = await Author.objects.select_related("books").paginate(1, 10).get( + books__year__isnull=True + ) + assert len(tolkien.books) == 1 + assert tolkien.books[0].year is None + assert tolkien.books[0].title == "The Hobbit" + tolkien = await Author.objects.select_related("books").get( books__year__isnull=False )