summaryrefslogtreecommitdiff
path: root/test/orm/test_evaluator.py
diff options
context:
space:
mode:
authorMike Bayer <mike_mp@zzzcomputing.com>2017-09-10 00:01:18 -0400
committerMike Bayer <mike_mp@zzzcomputing.com>2017-09-10 00:01:18 -0400
commitdb170dd4529c5176d38db649dd75427a932b47fe (patch)
treef7f25635bb520f34aa4d2b22d63d06592b58a00a /test/orm/test_evaluator.py
parentca2c42df6ba108289031ccecd030b7aa196a66d6 (diff)
downloadsqlalchemy-ticket_4073.tar.gz
Warn instead of raise for unmapped column that matches on keyticket_4073
Modified the change made to the ORM update/delete evaluator in :ticket:`3366` such that if an unmapped column expression is present in the update or delete, if the evaluator can match its name to the mapped columns of the target class, a warning is emitted, rather than raising UnevaluatableError. This is essentially the pre-1.2 behavior, and is to allow migration for applications that are currently relying upon this pattern. However, if the given attribute name cannot be matched to the columns of the mapper, the UnevaluatableError is still raised, which is what was fixed in :ticket:`3366`. Change-Id: I658ed0dbf485b7f8009774f9c12d9912447abd2a Fixes: #4073
Diffstat (limited to 'test/orm/test_evaluator.py')
-rw-r--r--test/orm/test_evaluator.py22
1 files changed, 19 insertions, 3 deletions
diff --git a/test/orm/test_evaluator.py b/test/orm/test_evaluator.py
index ffb8d8701..dc96dc15d 100644
--- a/test/orm/test_evaluator.py
+++ b/test/orm/test_evaluator.py
@@ -15,7 +15,7 @@ from sqlalchemy.orm import exc as orm_exc
from sqlalchemy.testing import assert_raises_message
from sqlalchemy.testing import is_
from sqlalchemy import inspect
-
+from sqlalchemy.testing import expect_warnings
compiler = evaluator.EvaluatorCompiler()
@@ -38,7 +38,8 @@ class EvaluateTest(fixtures.MappedTest):
def define_tables(cls, metadata):
Table('users', metadata,
Column('id', Integer, primary_key=True),
- Column('name', String(64)))
+ Column('name', String(64)),
+ Column('othername', String(64)))
@classmethod
def setup_classes(cls):
@@ -84,9 +85,24 @@ class EvaluateTest(fixtures.MappedTest):
eval_eq(User.name == None, # noqa
testcases=[(User(name='foo'), False), (User(name=None), True)])
- def test_raise_on_unannotated_column(self):
+ def test_warn_on_unannotated_matched_column(self):
User = self.classes.User
+ compiler = evaluator.EvaluatorCompiler(User)
+
+ with expect_warnings(
+ r"Evaluating non-mapped column expression 'Column\('othername'.* "
+ "onto ORM instances; this is a deprecated use case."):
+ meth = compiler.process(User.name == Column('othername', String))
+
+ u1 = User(id=5)
+ meth(u1)
+
+ def test_raise_on_unannotated_unmatched_column(self):
+ User = self.classes.User
+
+ compiler = evaluator.EvaluatorCompiler(User)
+
assert_raises_message(
evaluator.UnevaluatableError,
"Cannot evaluate column: foo",