mirror of
https://github.com/GSA/notifications-api.git
synced 2026-03-01 14:29:51 -05:00
When we're bulk updating, make sure we call `synchronize_session=False`, and make sure that we then commit before we try and access any ORM objects in the session that might be deleted. Tutorial time: when you delete, sqlalchemy needs to work out what to do with objects in the session. "evaluate", "fetch", or False (do nothing). It wants to remove items from the session if you're about to delete them, so that you don't get confused about the state of objects * evaluate compares the delete query to each item in the session in turn. this is the default. if you have lots in the session this could be super slow I guess but that's rarely the case for us. This can lead to errors if the column names are different to the model names, like on our notification and history models. * fetch runs the delete query as if it's a select, and then checks the results of that vs the session. This could be slow. * False doesn't do anything. This means the session will be stale and potentially will contain now-deleted items, until we call `commit` or `expire_all` on the session. https://docs.sqlalchemy.org/en/13/orm/query.html?highlight=query.update#sqlalchemy.orm.query.Query.delete