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
Can this work with AsyncSession?
I am trying to work with the examples but I cannot seem to be able to overwrite the sorter.
I get this error
fastapi_listing/sorter/page_sorter.py
File "/opt/pysetup/.venv/lib/python3.11/site-packages/fastapi_listing/sorter/page_sorter.py", line 20, in sort_dsc_util
query = query.order_by(inst_field.desc())
AttributeError: 'coroutine' object has no attribute 'order_by'
I have overwrite the get_default_read to work with async, but I cannot see how to do that in the page_sorter.
class VideoDao(GenericDao):
def __init__(self, db: AsyncSession) -> None:
super().__init__(db)
name = "videoresponse"
model = Videos
async def get_default_read(self, fields_to_read: Optional[list]):
query = await self.db.query(Videos)
return query
The text was updated successfully, but these errors were encountered:
Allow me to ask you a couple of questions first.
I don't think Asyncsession works with query api(correct me if I'm wrong)
you should have faced an error like AttributeError: 'async_sessionmaker' object has no attribute 'query'
but your code was able to call page_sorter
it doesn't support AsyncSession natively for now but there is a way around
you could use select statement at dao level and in page_builder you could pass async_session as extra_context
where you can do session.execute(stmt) and call all or fetchall method on your result.
Do you want me to add a working example for this workaround?
Or I think we can work on adding a support layer for AsyncSession.
Hello!
Can this work with AsyncSession?
I am trying to work with the examples but I cannot seem to be able to overwrite the sorter.
I get this error
I have overwrite the
get_default_read
to work with async, but I cannot see how to do that in the page_sorter.The text was updated successfully, but these errors were encountered: