regression in bulk update, evaluator disallows literal_column

Issue #4073 resolved
Michael Bayer
repo owner created an issue
from sqlalchemy import *
from sqlalchemy.orm import *
from sqlalchemy.ext.declarative import declarative_base

Base = declarative_base()

class A(Base):
    __tablename__ = 'a'
    id = Column(Integer, primary_key=True)
    x = Column(Integer)
    y = Column(Integer)

e = create_engine("sqlite://", echo=True)

s = Session(e)
s.add(A(x=1, y=2))

s.query(A).update({A.x: literal_column('y')})


Traceback (most recent call last):
  File "", line 22, in <module>
    s.query(A).update({A.x: literal_column('y')})
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/", line 3366, in update
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/", line 1324, in exec_
  File "/home/classic/dev/sqlalchemy/lib/sqlalchemy/orm/", line 1399, in _do_pre_synchronize
    "Could not evaluate current criteria in Python. "
sqlalchemy.exc.InvalidRequestError: Could not evaluate current criteria in Python. Specify 'fetch' or False for the synchronize_session parameter.

this affects openstack nova and the soft_delete() method in oslo.db which uses this.

Comments (2)

  1. Michael Bayer reporter

    Warn instead of raise for unmapped column that matches on key

    Modified the change made to the ORM update/delete evaluator in 🎫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 🎫3366.

    Change-Id: I658ed0dbf485b7f8009774f9c12d9912447abd2a Fixes: #4073

    → <<cset db170dd4529c>>

  2. Log in to comment