In documentation on .merge is written :https://docs.sqlalchemy.org/en/20/orm/session_api.html#sqlalchemy.orm.Session.merge that it is possible to pass extra options which lately will be applied into session.get. Is session.get documentation is written that is is possible to use with_for_update option https://docs.sqlalchemy.org/en/20/orm/session_api.html#sqlalchemy.orm.Session.get.params.with_for_update
place_model = type(place)
try:
async with session.begin_nested():
place_merged = await session.merge(place, options={'with_for_update': True})
except sa_exc.IntegrityError as err:
....
....
I have been trying to use it like this but got an exception - sqlalchemy.exc.ArgumentError: ExecutionOption Core or ORM object expected, got 'with_for_update'.
Question is - how to add option with_for_update into session.merge correctly?
This is a misunderstadning I think.
The merge docs state:
options – optional sequence of loader options which will be applied to the Session.get() method when the merge operation loads the existing version of the object from the database.
I believe this maps to the options parameter of Session.get
:
options – optional sequence of loader options which will be applied to the query, if one is emitted.
with_for_update is a separate parameter, it cannot be passed via Session.merge
.