GithubHelp home page GithubHelp logo

Comments (4)

lindycoder avatar lindycoder commented on August 21, 2024

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.

Goldziher avatar Goldziher commented on August 21, 2024

We should aim for backward compatible solutions. I'm thinking if the pessimistic setting etc.

Do you feel like implementing this?

from polyfactory.

roeeyn avatar roeeyn commented on August 21, 2024

So how should we handle the provided example then?

from polyfactory.

Goldziher avatar Goldziher commented on August 21, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.