Open Miguelme opened 2 years ago
Is it an error that occurred after attempting to create a table?
No, when trying to delete the resource given that the GET
is returning a row instead of the actual Item
sqlmodel (apparently).
This is the exact line where it fails:
await db.delete(await get_item(item_id, db))
With async you need this for get_item
, to add the scalar bit. At least with the new 2.0 style SQLAlchemy core api, which is included in 1.4.
from sqlalchemy.future import select #2.0 core style for async, https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html
stmt = select(dbmodel).where(dbmodel.id == obid)
res = await session.execute(stmt)
return res.unique().scalar_one()
Why is this difference only specific to the async style? Is there any place where I could find it documented to avoid it in the future?
SQLAlchemy async docs are at https://docs.sqlalchemy.org/en/14/orm/extensions/asyncio.html
First Check
Commit to Help
Example Code
Description
I'm trying to do some really silly implementation of a CRUD but I am not able to make it work using an Async Connection to the MySQL Database, the error I get is that the object is not being converted to a SQLModel but that it stays as a Row. It's the following:
Operating System
macOS
Operating System Details
No response
SQLModel Version
0.0.6
Python Version
3.9.9
Additional Context
I think what is happening is that the async connection is not set-up properly connected to the SQLModel implementation so it can get automatically converted to the SQLModel object but I'm not sure which should be the expected process. Please let me know if you need more information about it