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
The project I am working on has schemas used in the api and models which are stored in the database (using SQLAlchemy as interface).
The schemas and models are different because of reasons which are irrelevant to this issue.
Current behavior
I am implementing pagination, but the issue is that paginate() is expecting its items to be of the schema-type, and it knows this from the endpoint details, while I first fetch them as models on paginate.
I can go around this by transforming the items to the schema's. However, this is not ideal since I want to do some things inbetween those two actions (fetching items with paginate and transforming the items into the schema's).
Expected behavior
I would love to be able to specify somewhere which pydantic model the paginate function will expect.
The text was updated successfully, but these errors were encountered:
I guess you can try to use set_page function, it can be used with with statement to set page class for a specific context.
Here is an example:
@app.get('/users')defget_users(db: Session=Depends(get_db)) ->Page[UserOut]:
withset_page(Page[User]):
page=paginate(db, select(User).order_by(User.created_at))
# here you can do something with page, items will pe of User typereturnpage
The project I am working on has schemas used in the api and models which are stored in the database (using SQLAlchemy as interface).
The schemas and models are different because of reasons which are irrelevant to this issue.
Current behavior
I am implementing pagination, but the issue is that
paginate()
is expecting itsitems
to be of the schema-type, and it knows this from the endpoint details, while I first fetch them asmodels
onpaginate
.I can go around this by transforming the items to the schema's. However, this is not ideal since I want to do some things inbetween those two actions (fetching items with paginate and transforming the items into the schema's).
Expected behavior
I would love to be able to specify somewhere which pydantic model the
paginate
function will expect.The text was updated successfully, but these errors were encountered: