diff options
author | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-06-26 13:24:22 -0400 |
---|---|---|
committer | Mike Bayer <mike_mp@zzzcomputing.com> | 2017-06-26 13:49:49 -0400 |
commit | 9ac0f8119e34a696fbf711e00262e9c0851b749c (patch) | |
tree | f05beb1e57e70d4e286ac8b068f992f4fb52b59c /test | |
parent | e04594339c19c3cd8b8e0d96ce83e5ded961dbb7 (diff) | |
download | sqlalchemy-9ac0f8119e34a696fbf711e00262e9c0851b749c.tar.gz |
Support state expiration for with_expression(); rename deferred_expression
The attributeimpl for a deferred_expression does not
support a scalar loader, add new configurability so that
the impl can have this flag turned off. Document
that the with_expression() system currently does not
offer any deferred loading.
To eliminate confusion over "deferred", which refers to
lazy loading of column attributes, and "with_expression",
which refers to an attribute that is explicitly at
query time only, rename deferred_expression to query_expression.
Change-Id: I07c4a050ed68c79ccbde9492e9de1630b7470d74
Diffstat (limited to 'test')
-rw-r--r-- | test/orm/test_deferred.py | 55 |
1 files changed, 51 insertions, 4 deletions
diff --git a/test/orm/test_deferred.py b/test/orm/test_deferred.py index 9c2dc4c8b..9295399bc 100644 --- a/test/orm/test_deferred.py +++ b/test/orm/test_deferred.py @@ -3,7 +3,7 @@ from sqlalchemy import testing, util from sqlalchemy.orm import mapper, deferred, defer, undefer, Load, \ load_only, undefer_group, create_session, synonym, relationship, Session,\ joinedload, defaultload, aliased, contains_eager, with_polymorphic, \ - deferred_expression, with_expression + query_expression, with_expression from sqlalchemy.testing import eq_, AssertsCompiledSQL, assert_raises_message from test.orm import _fixtures from sqlalchemy.testing.schema import Column @@ -886,7 +886,7 @@ class WithExpressionTest(fixtures.DeclarativeMappedTest): x = Column(Integer) y = Column(Integer) - my_expr = deferred_expression() + my_expr = query_expression() bs = relationship("B", order_by="B.id") @@ -897,7 +897,7 @@ class WithExpressionTest(fixtures.DeclarativeMappedTest): p = Column(Integer) q = Column(Integer) - b_expr = deferred_expression() + b_expr = query_expression() @classmethod def insert_data(cls): @@ -972,4 +972,51 @@ class WithExpressionTest(fixtures.DeclarativeMappedTest): def go(): eq_(a1.my_expr, None) - self.assert_sql_count(testing.db, go, 0)
\ No newline at end of file + self.assert_sql_count(testing.db, go, 0) + + def test_dont_explode_on_expire_individual(self): + A = self.classes.A + + s = Session() + q = s.query(A).options( + with_expression(A.my_expr, A.x + A.y)).filter(A.x > 1).\ + order_by(A.id) + + a1 = q.first() + + eq_(a1.my_expr, 5) + + s.expire(a1, ['my_expr']) + + eq_(a1.my_expr, None) + + # comes back + q = s.query(A).options( + with_expression(A.my_expr, A.x + A.y)).filter(A.x > 1).\ + order_by(A.id) + q.first() + eq_(a1.my_expr, 5) + + def test_dont_explode_on_expire_whole(self): + A = self.classes.A + + s = Session() + q = s.query(A).options( + with_expression(A.my_expr, A.x + A.y)).filter(A.x > 1).\ + order_by(A.id) + + a1 = q.first() + + eq_(a1.my_expr, 5) + + s.expire(a1) + + eq_(a1.my_expr, None) + + # comes back + q = s.query(A).options( + with_expression(A.my_expr, A.x + A.y)).filter(A.x > 1).\ + order_by(A.id) + q.first() + eq_(a1.my_expr, 5) + |