Title: Listing or returning items with UoW raises sqlalchemy.orm.exc.DetachedInstanceError · Issue #63 · cosmicpython/code · GitHub
Open Graph Title: Listing or returning items with UoW raises sqlalchemy.orm.exc.DetachedInstanceError · Issue #63 · cosmicpython/code
X Title: Listing or returning items with UoW raises sqlalchemy.orm.exc.DetachedInstanceError · Issue #63 · cosmicpython/code
Description: 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 it...
Open Graph Description: 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:...
X Description: 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.Ite...
Opengraph URL: https://github.com/cosmicpython/code/issues/63
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Listing or returning items with UoW raises sqlalchemy.orm.exc.DetachedInstanceError","articleBody":"Hi. I have a simple `list` endpoint as follows:\r\n\r\n\r\n```python\r\n@app.get(\"/items/\", response_model=list[schemas.Item])\r\nasync def read_items(uow: AbstractUnitOfWork = Depends(get_uow)) -\u003e List[models.Item]:\r\n with uow:\r\n items = uow.repo.list()\r\n return items\r\n```\r\n\r\n`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. \r\n\r\nI would expect such a dataclass not to mutate since it is not an ORM model.\r\nWhat would be the best approach in this case? \r\n\r\nThe same applies for the creation of an item.\r\n\r\nThanks!","author":{"url":"https://github.com/sevetseh28","@type":"Person","name":"sevetseh28"},"datePublished":"2023-03-22T21:30:19.000Z","interactionStatistic":{"@type":"InteractionCounter","interactionType":"https://schema.org/CommentAction","userInteractionCount":2},"url":"https://github.com/63/code/issues/63"}
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:f0d386c1-5936-6327-6c48-c57c75147d37 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | D244:2C62EA:F6C07F:154EC6F:69776C73 |
| html-safe-nonce | c01b7b273f184d3a5ebaeca2f6353be3bc62d3278b4a6ca55c294d2c3e9becb8 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJEMjQ0OjJDNjJFQTpGNkMwN0Y6MTU0RUM2Rjo2OTc3NkM3MyIsInZpc2l0b3JfaWQiOiI4NzU5NzczMDU4MjQwNTcyNTMxIiwicmVnaW9uX2VkZ2UiOiJpYWQiLCJyZWdpb25fcmVuZGVyIjoiaWFkIn0= |
| visitor-hmac | 1369261719e85820939453bcf82243808591aa1b6e3b47cd4902413f5bc9309b |
| hovercard-subject-tag | issue:1636524606 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/cosmicpython/code/63/issue_layout |
| twitter:image | https://opengraph.githubassets.com/af5dab247390930422cb3ce256c49faf9c9b280cb8248e7c08b8baa04205bb41/cosmicpython/code/issues/63 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/af5dab247390930422cb3ce256c49faf9c9b280cb8248e7c08b8baa04205bb41/cosmicpython/code/issues/63 |
| og:image:alt | 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:... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sevetseh28 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 425384cc392ce2ddd1a7a0c1e7043ab4192d4c04452a2ed7f2f38d2fa9293b5a |
| turbo-cache-control | no-preview |
| go-import | github.com/cosmicpython/code git https://github.com/cosmicpython/code.git |
| octolytics-dimension-user_id | 47350834 |
| octolytics-dimension-user_login | cosmicpython |
| octolytics-dimension-repository_id | 169221290 |
| octolytics-dimension-repository_nwo | cosmicpython/code |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 169221290 |
| octolytics-dimension-repository_network_root_nwo | cosmicpython/code |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 72de26f7ca9bdb0559ebf1e63e6c685ee2c520ce |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
Links:
Viewport: width=device-width