Code Monkey home page Code Monkey logo

Comments (5)

vitalik avatar vitalik commented on May 30, 2024 1

@ddahan yeah.. well the thing is that pydantic now asks to configure this using attribute model_config

so for now do it like `model_config = {'extra': 'forbid'}

but I guess that is a bit confusing problem - I will think about it

from django-ninja.

vitalik avatar vitalik commented on May 30, 2024 1

@ddahan keep in mind - class Config is deprecated in pydantic and will be removed - so better use model_config = {'extra': 'forbid'}

from django-ninja.

ddahan avatar ddahan commented on May 30, 2024

Thanks vitalik. This works:

class BadgeSchemaInUpdate(ModelSchema):
    class Meta:
        model = Badge
        fields = ("expiration", "is_active")
        fields_optional = ("expiration", "is_active")

    model_config = {"extra": "forbid"}

And this works too (I suppose it does the same behind the scene):

class BadgeSchemaInUpdate(ModelSchema):
    class Meta:
        model = Badge
        fields = ("expiration", "is_active")
        fields_optional = ("expiration", "is_active")

    class Config(Schema.Config):
        extra = "forbid"

As you said, it's a little confusing, but IMO the main issue is that it's not documented right now.
I can see at least here a usage of the former usage.

I suggest not closing the issue, at least until the documentation is updated.
Thanks for your work.

from django-ninja.

vitalik avatar vitalik commented on May 30, 2024

for now I see 2 options:

  • copy all pydantic options that user put's to Meta to model_config
  • or throw an error saying that model_config should be used if user tries to put something into Meta

from django-ninja.

ddahan avatar ddahan commented on May 30, 2024

I'm absolutely not trustworthy with this piece of advice, as I don't know ninja and pydantic that much, but...
I guess it would depends on how users should know about Pydantic itself when using django-ninja.

If you want users to know about all possibilities offered by Pydantic, and you want to split responsibilities, it may be a good idea to split ninja parts and pydantic parts, with links to Pydantic in the ninja documentation.

On the other hand, if you want ninja to act as a wrapper around Pydantic, sothat users don't need to know about Pydantic at all, I'd create syntax sugar like copying all pydantic options that user put's to Meta to model_config.

I suppose the worst case scenario would be to not take a decision at all and mix both visions.

from django-ninja.

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.