bmuller / twistar

Twistar is an object-relational mapper (ORM) for Python that uses the Twisted library to provide asynchronous DB interaction.

Home Page:http://findingscience.com/twistar

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

joinWheres should use parenthesis to preserve precedence

flaviogrossi opened this issue · comments

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.

Thanks - fixed in c2cb3df and added your test.