…when I try to do a query that looks like this:
Session().query(MyMappedClass).update({MyMappedClass.time:func.now()})
I get:
InvalidRequestError: Could not evaluate current criteria in Python. Specify 'fetch' or False for the synchronize_session parameter.
But if I do:
Session().query(MyMappedClass).update({MyMappedClass.time:'now()'})
…it works. Anyone know why?
this is explained in the documentation for update()
update() by default would like to refresh those objects cached in the Session without doing a database round trip.
func.now()is a SQL function that requires this round trip to proceed. Sending in the string"now()"is not what you want, as this will set the value of the field to the string “now()”, and will not actually use the SQL time function. You should instead pass synchronize_session=False to update().