Q: SQLAlchemy ORM: Using func in update I am trying to use func in an update statement, but I'm getting an InvalidRequest error (stacktrace below). Here's the code:
session.query(C).filter(
    z == True,
).update({
    C.x: func.sqrt((C.y1 + C.y2) * 0.675)
})

And here's the stacktrace:
  File "/var/xxx/vagrant-env/local/lib/python2.7/site-packages/sqlalchemy/orm/query.py", line 3288, in update
    update_op.exec_()
  File "/var/xxx/vagrant-env/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 1167, in exec_
    self._do_pre_synchronize()
  File "/var/xxx/vagrant-env/local/lib/python2.7/site-packages/sqlalchemy/orm/persistence.py", line 1236, 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.

I tried with both func.sqrt and func.round but they both give the error above. Any thoughts on what I'm doing wrong?

A: You have to specify synchronize_session strategy - False,'fetch' or implement evaluate. Just add it as a parameter, for example
session.query(C).filter(
    z == True,
).update({
    C.x: func.sqrt((C.y1 + C.y2) * 0.675)
}, synchronize_session='fetch')

