Giter VIP home page Giter VIP logo

Comments (5)

whoiswes avatar whoiswes commented on May 14, 2024

FYI, by accident I got this working. If you change 'self' to the name of the schema you're self-referencing, APISpec doesn't blow up.

Like so:

class EntitySchema(ModelSchema):
    children = fields.Nested('EntitySchema', many=True)
    class Meta:
        model = Entity
        sqla_session = session
        include_fk = True

Not sure if this would be expected or desired behavior so leaving this open for now.

from apispec.

sloria avatar sloria commented on May 14, 2024

Thanks for the update, @whoiswes . I'm glad you found a workaround, but this still looks to be a bug--passing 'self' should not break the code.

I would be open to a PR for this.

from apispec.

sloria avatar sloria commented on May 14, 2024

This bug is now fixed on dev.

from apispec.

Chris2048 avatar Chris2048 commented on May 14, 2024

Hi, Can you explain to me the part of this fix:

is_unbound_self_referencing = not getattr(field, 'parent', None) and field.nested == 'self'

How might a self-referencing Nested field be 'bounded'?
Is the test for a parent is the same as a test for being an instance of SchemaABC (top-level abs baseclass)?

I am getting a MaxRecursion error on a self-referencing Nested field. This is fixed by adding a ref, but I'm curious why it is not USR without - the test for there being no parent fails, so the code here doesn't seem to handle.

Regards.

from apispec.

Chris2048 avatar Chris2048 commented on May 14, 2024

oooh, I think I see now - it if you supply a definition via:

spec.definition('foo', schema=FooSchema)

It will then be a "top-level" object since it has its own definition.
Then the name ('foo') is used to fill in the ref.

Is it possible to raise an exception when the object is self-referential but not top-level?
i.e."Self-referencing schema must provide named definition".

Incidentally, what happens when there are Schema that don't involve self-reference, but are recursive, e.g. involving two elements that refer to each other, A -> B -> A -> B -> A -> ...

If neither provides a definition then the same MaxRecursion will occur, without a Nested 'self'?

Regards.

from apispec.

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.