Repository navigation
awaitable_attrs in sqlmodel v 0.0.24 not available #1400
Replies: 1 comment
|
from sqlalchemy.ext.asyncio import AsyncAttrs
print(issubclass(User, AsyncAttrs))If it does not, add from sqlalchemy.ext.asyncio import AsyncAttrs
from sqlmodel import SQLModel
# Class-header change; retain your existing User model body.
class User(AsyncAttrs, SQLModel, table=True):
...You can also put the mixin on a shared non-table SQLModel base inherited by your table models. If you already have a UserBase, retain that base instead of replacing it and losing its fields. Then, while return await user.awaitable_attrs.groupsSQLAlchemy added I checked the SQLModel base definitions in 0.0.22 and 0.0.24: neither base adds |
Uh oh!
There was an error while loading. Please reload this page.
First Check
Commit to Help
Example Code
Description
I have a toy Fast API project (using sqlmodel for db interactions) with an endpoint that returns a user's groups. This works fine in 0.0.22 but when using 0.0.24 I get an Attribute error (see below) . I tried looking for info about awaitable attrs in the release notes but couldn't find anything.
I understand I can do selectinload / joinedload etc to solve my issue in this instance. Was the behaviour of lazy loading (in an async context) changed? If so, how can it be done now?
File "/usr/local/lib/python3.12/site-packages/pydantic/main.py", line 989, in getattr
raise AttributeError(f'{type(self).name!r} object has no attribute {item!r}')
AttributeError: 'User' object has no attribute 'awaitable_attrs'
Operating System
Linux
Operating System Details
No response
SQLModel Version
0.0.24
Python Version
3.12
Additional Context
No response
All reactions