You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Listing or returning items with UoW raises sqlalchemy.orm.exc.DetachedInstanceError #63
items is a list of models.Item which is my domain model (dataclass). But when exiting the uow (closing the session) the items' attributes are refreshed by the ORM automatically and I get the sqlalchemy.orm.exc.DetachedInstanceError exception.
I would expect such a dataclass not to mutate since it is not an ORM model.
What would be the best approach in this case?
You have multiple options in this case, including the one @sevetseh28 provided. Other options:
Return your list inside the with block
Set expire_on_commit=False when creating the session. This will disable the reloading of attributes after commit. I think it's safe to disable it because a handler shouldn't reload anything after commiting anyways as the aggregate must be transactionally consistent and complete before committing.
Activity
sevetseh28 commentedon Mar 22, 2023
Maybe using
schemas.Itemas a DTO like this, and convert:wdyt?
instanceofmel commentedon Mar 6, 2024
A little late, but for future readers:
You have multiple options in this case, including the one @sevetseh28 provided. Other options:
withblockexpire_on_commit=Falsewhen creating the session. This will disable the reloading of attributes after commit. I think it's safe to disable it because a handler shouldn't reload anything after commiting anyways as the aggregate must be transactionally consistent and complete before committing.