Skip to content

Conversation

@daxxog
Copy link

@daxxog daxxog commented Aug 26, 2022

Pydantic has a way to specify a function that provides a default value for a field.

This pull request adds support for this in fastapi-crudrouter, for primary keys that utilize this.

Example:

from secrets import choice from pydantic import BaseModel, Field from fastapi import FastAPI from fastapi_crudrouter import MemoryCRUDRouter as CRUDRouter class Potato(BaseModel): id: int = Field(default_factory=lambda: choice(range(0,3))) color: str mass: float app = FastAPI() app.include_router(CRUDRouter(schema=Potato))
@vercel
Copy link

vercel bot commented Aug 26, 2022

The latest updates on your projects. Learn more about Vercel for Git ↗︎

Name Status Preview Updated
fastapi-crudrouter ✅ Ready (Inspect) Visit Preview Jan 11, 2023 at 1:32PM (UTC)
@awtkns
Copy link
Owner

awtkns commented Sep 14, 2022

@daxxog thanks for this! Sorry for the delay. Would you be willing to add a test or two for this prior to merging?

@daxxog
Copy link
Author

daxxog commented Sep 15, 2022

@awtkns Sure I can do that!

@daxxog
Copy link
Author

daxxog commented Sep 17, 2022

@awtkns Is this along the lines of what you are looking for? 8000bac

@daxxog
Copy link
Author

daxxog commented Sep 17, 2022

@awtkns Is this along the lines of what you are looking for? 8000bac

@awtkns Disregard my previous comment. I ran coverage and realized my diff to the tests wasn't even covering my feature. I got the tests to actually run against my feature, and then discovered a few issues, which I fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

2 participants