Comments (4)
If this was
class A(BaseModel):
b: "B"
class B(BaseModel):
a: A
It would be downright impossible do instantiate this anyway... so "true" recursion is really possible unless there's an "out".
In the example you have, the "out" is the "empty list" in the example from the startlite bug, the "out" is a None
on the subentity.
My recommendation would be that anything that can be empty is empty unless specified otherwise, and everything Optional[]
is None, unless specified otherwise.
I know this would break the current behaviour and people might rely on this behaviour that sometimes Optional
stuff is None
and dict
/list
have 1 element and sets
have a lot of letters.
For the record, i personally do make my ModelFactories
have a Use(list)
or similar for any "emptyable" field. My philosophy is that worst case should be handled, and if you NEED a value in there it's because you're testing what happens with it, so might as well define it clearly in your test :)
A backward compatible option could be a way to turn this ModelFactory
into a "pessimist" mode that would do what I do making stuff empty or None, which could resolve these recursive references.
from polyfactory.
We should aim for backward compatible solutions. I'm thinking if the pessimistic setting etc.
Do you feel like implementing this?
from polyfactory.
So how should we handle the provided example then?
from polyfactory.
So how should we handle the provided example then?
I think to add a max recursion value to a factory with a default. Upon identifying more than the max recursion, switch the value to none, if it's optional, otherwise raise a verbose error with user instructions
from polyfactory.
Related Issues (20)
- Enhancement: add support for Odmantic 1.0
- Use defaults values from BaseModel in ModelFactory HOT 4
- Support for relationship building models in `SQLAlchemyFactory` HOT 10
- Bug: Incomplete Dependency Specification HOT 1
- Bug: settings `__set_as_default_factory_for_type__ ` to `True` on base factory fails
- Bug: Pydantic fields with constraints and multiple type hints cause `ParameterException` HOT 1
- Bug: Optional constrained types do not work HOT 8
- Bug: ModelFactory can not generate list of classes with a Pydantic field alias HOT 1
- bug: support column.type `impl` attribute HOT 1
- Bug: Setting `ge` and `multiple_of` but not `le` constraints causes invalid values to be generated HOT 2
- Docs: Add example to use `PydanticFactory` with SQLAlchemy persistence HOT 5
- Bug: Data generated incorrectly from nested Annotated HOT 4
- Bug: Try to use SQLAlchemyFactory for model with column_property HOT 4
- Bug: UUIDBase ID Value Changed from UUID to Bytes HOT 4
- Enhancement: Support for dictionaries with Pydantic models as value, e.g. dict[str, PydanticClass] HOT 1
- Bug: Invalid Coverage for Optional Fields with Annotated Constraint
- Bug: pyright incompatability HOT 1
- Any not supported in provider_map
- Doubt in usage of polyfactory HOT 1
- Bug: Optional lists in coverage produce nested lists HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from polyfactory.