Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Listing or returning items with UoW raises sqlalchemy.orm.exc.DetachedInstanceError #63

Copy link
Copy link
@sevetseh28

Description

@sevetseh28
Issue body actions

Hi. I have a simple list endpoint as follows:

@app.get("/items/", response_model=list[schemas.Item])
async def read_items(uow: AbstractUnitOfWork = Depends(get_uow)) -> List[models.Item]:
    with uow:
        items = uow.repo.list()
    return items

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?

The same applies for the creation of an item.

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions

      Morty Proxy This is a proxified and sanitized view of the page, visit original site.