joinWheres should use parenthesis to preserve precedence
flaviogrossi opened this issue · comments
Flavio Grossi commented
hi,
i think in twistar.utils.joinWheres a couple of parenthesis are missing. It should be:
statement = ["(%s) %s (%s)" % (wone[0], joiner, wtwo[0])]
testcase:
@inlineCallbacks
def test_joinWheres_precedence(self):
# this relies on initDB default test setup
yield User(first_name="Second").save()
first = ['first_name = ?', "First"]
last = ['last_name = ?', "Last"]
second = ['first_name = ?', "Second"]
last_or_second = twistar.utils.joinWheres([last, second], joiner='OR')
where = twistar.utils.joinWheres([first, last_or_second], joiner='AND')
results = yield User.count(where=where)
self.assertEqual(1, results)
the result is different wheter you have parenthesis in joinWheres or not.
Brian Muller commented
Thanks - fixed in c2cb3df and added your test.