Hi,
I use FastAPI with a 'typical' structure: Pydantic schemas are converted to SQLAlchemy models.
For tests, currently, SQLAlchemy models are created in fixtures. Obviously, as the amount of models and validations grows, this doesn't scale. Therefore, I will use per-test objects created by factories.
polyfactory looks ideal, but one thing is missing: I would like to pass a Pydantic schema (PydanticFactory
), then convert it to an SQLAlchemy model and create it, using a custom (CRUD layer) implementation.
Reason: Pydantic schemas validate business logic that should not be violated in tests (which happens by creating SQLAlchemy models with only data validation).
This looks relatively easy to implement by passing a custom handler to __sync_persistence__
on a factory (https://polyfactory.litestar.dev/latest/usage/configuration.html#persistence-handlers). (Still need to figure out how to subclass my factories from a base class so I don't have to repeat that...)
Instead of writing the implementation myself, would the maintainers be interested in adding a first-party supported example to the documentation? I could imagine this use case is quite common, as this is relevant for basically all larger FastAPI/Pydantic/SQLAlchemy projects.
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too