- changed status to resolved
query.update() does not accept instrumented attributes
Issue #1262
resolved
Query.update's docstring reads:
Updates rows matched by this query in the database. The values parameter takes a dictionary with object attributes as keys and literal values or sql expressions as value.
but currently only string keys are accepted. (column name? property name?) Either the doc should be updated or Class.attr should be accepted, allowing the below test to pass:
Index: test/orm/query.py
===================================================================
--- test/orm/query.py (revision 5527)
+++ test/orm/query.py (working copy)
@@ -2665,6 +2665,17 @@
eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27](25,37,29,27)))
@testing.resolve_artifact_names
+ def test_update_by_attribute(self):
+ sess = create_session(bind=testing.db, autocommit=False)
+
+ john,jack,jill,jane = sess.query(User).order_by(User.id).all()
+ sess.query(User).filter(User.age > 29).update(
+ {User.age: User.age - 10}, synchronize_session='evaluate')
+
+ eq_([jack.age, jill.age, jane.age](john.age,), [25,37,29,27](25,37,29,27))
+ eq_(sess.query(User.age).order_by(User.id).all(), zip([25,37,29,27](25,37,29,27)))
+
+ @testing.resolve_artifact_names
def test_update_with_bindparams(self):
sess = create_session(bind=testing.db, autocommit=False)
Comments (3)
-
repo owner -
repo owner - removed milestone
Removing milestone: 0.5.0 (automated comment)
-
repo owner - edited description
- removed responsible
- Log in to comment
bd23baf4ac0f9dd520120445594bd00f1b760f4b