From c0f7c4ca2ddabb33a5d7dcfd87dfe9f8059844bc Mon Sep 17 00:00:00 2001 From: Harry Marr Date: Sun, 3 Oct 2010 23:22:36 +0100 Subject: [PATCH] Fixed error in empty property on QCombination --- mongoengine/queryset.py | 2 +- tests/queryset.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/mongoengine/queryset.py b/mongoengine/queryset.py index 21bd44d0..2c822c75 100644 --- a/mongoengine/queryset.py +++ b/mongoengine/queryset.py @@ -158,7 +158,7 @@ class QCombination(QNode): @property def empty(self): - return not bool(self.query) + return not bool(self.children) class NewQ(QNode): diff --git a/tests/queryset.py b/tests/queryset.py index 6d3114e5..6a337640 100644 --- a/tests/queryset.py +++ b/tests/queryset.py @@ -1417,6 +1417,7 @@ class NewQTest(unittest.TestCase): def test_and_combination(self): class TestDoc(Document): x = IntField() + y = StringField() # Check than an error is raised when conflicting queries are anded def invalid_combination(): @@ -1432,6 +1433,15 @@ class NewQTest(unittest.TestCase): query = (q1 & q2).to_query(TestDoc) self.assertEqual(query, {'x': {'$lt': 7, '$gt': 3}}) + # More complex nested example + query = NewQ(x__lt=100) & NewQ(y__ne='NotMyString') + query &= NewQ(y__in=['a', 'b', 'c']) & NewQ(x__gt=-100) + mongo_query = { + 'x': {'$lt': 100, '$gt': -100}, + 'y': {'$ne': 'NotMyString', '$in': ['a', 'b', 'c']}, + } + self.assertEqual(query.to_query(TestDoc), mongo_query) + def test_or_combination(self): class TestDoc(Document): x = IntField()