.. changelog::
:version: 1.0.0
+ .. change::
+ :tags: bug, orm
+ :tickets: 3117
+
+ The "evaulator" for query.update()/delete() won't work with multi-table
+ updates, and needs to be set to `synchronize_session=False` or
+ `synchronize_session='fetch'`; this now raises an exception, with a
+ message to change the synchronize setting.
+ This is upgraded from a warning emitted as of 0.9.7.
+
.. change::
:tags: removed
class EvaluatorCompiler(object):
+ def __init__(self, target_cls=None):
+ self.target_cls = target_cls
+
def process(self, clause):
meth = getattr(self, "visit_%s" % clause.__visit_name__, None)
if not meth:
def visit_column(self, clause):
if 'parentmapper' in clause._annotations:
- key = clause._annotations['parentmapper'].\
- _columntoproperty[clause].key
+ parentmapper = clause._annotations['parentmapper']
+ if self.target_cls and not issubclass(
+ self.target_cls, parentmapper.class_):
+ raise UnevaluatableError(
+ "Can't evaluate criteria against alternate class %s" %
+ parentmapper.class_
+ )
+ key = parentmapper._columntoproperty[clause].key
else:
key = clause.key
+
get_corresponding_attr = operator.attrgetter(key)
return lambda obj: get_corresponding_attr(obj)
def _do_pre_synchronize(self):
query = self.query
+ target_cls = query._mapper_zero().class_
+
try:
- evaluator_compiler = evaluator.EvaluatorCompiler()
+ evaluator_compiler = evaluator.EvaluatorCompiler(target_cls)
if query.whereclause is not None:
eval_condition = evaluator_compiler.process(
query.whereclause)
"Could not evaluate current criteria in Python. "
"Specify 'fetch' or False for the "
"synchronize_session parameter.")
- target_cls = query._mapper_zero().class_
#TODO: detect when the where clause is a trivial primary key match
self.matched_objects = [
test_needs_autoincrement=True),
Column('name', String(32)),
Column('age', Integer))
-
@classmethod
def setup_classes(cls):
class User(cls.Comparable):
pass
-
@classmethod
def insert_data(cls):
users = cls.tables.users
])
)
+ def test_no_eval_against_multi_table_criteria(self):
+ User = self.classes.User
+ Document = self.classes.Document
+
+ s = Session()
+
+ q = s.query(User).filter(User.id == Document.user_id)
+ assert_raises_message(
+ exc.InvalidRequestError,
+ "Could not evaluate current criteria in Python.",
+ q.update,
+ {"name": "ed"}
+ )
+
+
@testing.requires.update_where_target_in_subquery
def test_update_using_in(self):
Document = self.classes.Document
filter(User.id == 2).update({
Document.samename: 'd_samename',
User.samename: 'u_samename'
- }
+ }, synchronize_session=False
)
eq_(
s.query(User.id, Document.samename, User.samename).