Skip to content

Commit

Permalink
Pony ORM Release 0.7.5 (2018-07-24)
Browse files Browse the repository at this point in the history
# Bugfixes

* `query.where` and `query.filter` method bug introduced in 0.7.4 was fixed
  • Loading branch information
kozlovsky committed Jul 24, 2018
2 parents d1f789a + 607b8d9 commit 628c607
Show file tree
Hide file tree
Showing 6 changed files with 131 additions and 32 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
# Pony ORM Release 0.7.5 (2018-07-24)

## Bugfixes

* `query.where` and `query.filter` method bug introduced in 0.7.4 was fixed


# Pony ORM Release 0.7.4 (2018-07-23)

## Major features
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,4 @@ Meet the PonyORM team, chat with the community members, and get your questions a
Join our newsletter at [ponyorm.com](https://ponyorm.com).
Reach us on [Twitter](https://twitter.com/ponyorm).

Copyright (c) 2016 Pony ORM, LLC. All rights reserved. team (at) ponyorm.com
Copyright (c) 2018 Pony ORM, LLC. All rights reserved. team (at) ponyorm.com
2 changes: 1 addition & 1 deletion pony/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import sys
from os.path import dirname

__version__ = '0.7.4'
__version__ = '0.7.5'

def detect_mode():
try: import google.appengine
Expand Down
67 changes: 37 additions & 30 deletions pony/orm/sqltranslation.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,9 +245,7 @@ def check_name_is_single():
translator.sqlquery = monad._subselect(translator.sqlquery, extract_outer_conditions=False)
tableref = monad.tableref
else: assert False # pragma: no cover
new_namespace = translator.namespace.copy()
new_namespace[name] = ObjectIterMonad(translator, tableref, entity)
translator.namespace_stack.append(new_namespace)
translator.namespace[name] = ObjectIterMonad(translator, tableref, entity)
elif node.external:
iterable = translator.root_translator.vartypes[translator.filter_num, node.src]
if isinstance(iterable, SetType):
Expand Down Expand Up @@ -800,35 +798,44 @@ def apply_lambda(translator, filter_num, order_by, func_ast, argnames, original_

if not original_names:
assert argnames
translator.namespace_stack.append({name: monad for name, monad in izip(argnames, translator.expr_monads)})
namespace = {name: monad for name, monad in izip(argnames, translator.expr_monads)}
elif argnames:
translator.namespace_stack.append({name: translator.namespace[name] for name in argnames})

translator.dispatch(func_ast)
if isinstance(func_ast, ast.Tuple): nodes = func_ast.nodes
else: nodes = (func_ast,)
if order_by:
translator.inside_order_by = True
new_order = []
for node in nodes:
if isinstance(node.monad, SetMixin):
t = node.monad.type.item_type
if isinstance(type(t), type): t = t.__name__
throw(TranslationError, 'Set of %s (%s) cannot be used for ordering'
% (t, ast2src(node)))
new_order.extend(node.monad.getsql())
translator.order[:0] = new_order
translator.inside_order_by = False
namespace = {name: translator.namespace[name] for name in argnames}
else:
for node in nodes:
monad = node.monad
if isinstance(monad, AndMonad): cond_monads = monad.operands
else: cond_monads = [ monad ]
for m in cond_monads:
if not m.aggregated: translator.conditions.extend(m.getsql())
else: translator.having_conditions.extend(m.getsql())
translator.vars = None
return translator
namespace = None
if namespace is not None:
translator.namespace_stack.append(namespace)

try:
translator.dispatch(func_ast)
if isinstance(func_ast, ast.Tuple): nodes = func_ast.nodes
else: nodes = (func_ast,)
if order_by:
translator.inside_order_by = True
new_order = []
for node in nodes:
if isinstance(node.monad, SetMixin):
t = node.monad.type.item_type
if isinstance(type(t), type): t = t.__name__
throw(TranslationError, 'Set of %s (%s) cannot be used for ordering'
% (t, ast2src(node)))
new_order.extend(node.monad.getsql())
translator.order[:0] = new_order
translator.inside_order_by = False
else:
for node in nodes:
monad = node.monad
if isinstance(monad, AndMonad): cond_monads = monad.operands
else: cond_monads = [ monad ]
for m in cond_monads:
if not m.aggregated: translator.conditions.extend(m.getsql())
else: translator.having_conditions.extend(m.getsql())
translator.vars = None
return translator
finally:
if namespace is not None:
ns = translator.namespace_stack.pop()
assert ns is namespace
def preGenExpr(translator, node):
inner_tree = node.code
translator_cls = translator.__class__
Expand Down
5 changes: 5 additions & 0 deletions pony/orm/tests/test_hybrid_methods_and_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,11 @@ def test12(self):

@db_session
def test13(self):
persons = select(p.full_name for p in Person if count(p.cars_by_color1('white')) > 1)
self.assertEqual(set(persons), {'Alexander Tischenko'})

@db_session
def test14(self):
# This test checks if accessing function-specific globals works correctly
persons = select(p.incorrect_full_name for p in Person if p.has_car)[:]
self.assertEqual(set(persons), {'Alexander ***', 'Alexei ***', 'Alexander ***'})
Expand Down
80 changes: 80 additions & 0 deletions pony/orm/tests/test_select_from_select_queries.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,86 @@ def test_22(self):
objects = select(s for s in Student if s.scholarship > 200)[:] # not query, but query result
q = select(s.first_name for s in objects)

@db_session
def test_23(self):
q = select(s for s in Student)
q2 = q.filter(lambda x: x.scholarship > 450)
q3 = q2.where(lambda s: s.scholarship < 520)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_24(self):
q = select(s for s in Student)
q2 = q.where(lambda s: s.scholarship > 450)
q3 = q2.filter(lambda x: x.scholarship < 520)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_25(self):
q = Student.select().filter(lambda x: x.scholarship > 450)
q2 = select(s for s in q)
q3 = q2.where(lambda s: s.scholarship < 520)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_26(self):
q = Student.select().filter(lambda x: x.scholarship > 450)
q2 = q.where(lambda s: s.scholarship < 520)
q3 = select(s for s in q2)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_27(self):
q = Student.select().where(lambda s: s.scholarship > 450)
q2 = select(s for s in q)
q3 = q2.filter(lambda x: x.scholarship < 520)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_28(self):
q = Student.select().where(lambda s: s.scholarship > 450)
q2 = q.filter(lambda x: x.scholarship < 520)
q3 = select(s for s in q2)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_29(self):
q = select(s for s in Student)
q2 = q.where(lambda s: s.scholarship > 450)
q3 = q2.where(lambda s: s.scholarship < 520)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_30(self):
q = select(s for s in Student)
q2 = q.filter(lambda x: x.scholarship > 450)
q3 = q2.filter(lambda z: z.scholarship < 520)
self.assertEqual(set(q3), {Student[3]})

@db_session
def test_31(self):
q = select(s for s in Student).order_by(lambda s: s.scholarship)
q2 = q.where(lambda s: s.scholarship > 450)
self.assertEqual(set(q2), {Student[3]})

@db_session
def test_32(self):
q = select(s for s in Student).order_by(lambda s: s.scholarship)
q2 = q.filter(lambda z: z.scholarship > 450)
self.assertEqual(set(q2), {Student[3]})

@db_session
def test_33(self):
q = select(s for s in Student).sort_by(lambda x: x.scholarship)
q2 = q.where(lambda s: s.scholarship > 450)
self.assertEqual(set(q2), {Student[3]})

@db_session
def test_34(self):
q = select(s for s in Student).sort_by(lambda x: x.scholarship)
q2 = q.filter(lambda s: s.scholarship > 450)
self.assertEqual(set(q2), {Student[3]})


if __name__ == '__main__':
unittest.main()

0 comments on commit 628c607

Please sign in to comment.