Comments (5)
@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.
@ddahan keep in mind - class Config
is deprecated in pydantic and will be removed - so better use model_config = {'extra': 'forbid'}
from django-ninja.
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.
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.
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)
- Overriding JSON schema title and summary without using `Field` HOT 1
- [BUG] CSRF Fails with Django Auth HOT 16
- [BUG] Order of operations affect response and request schemas HOT 1
- Documentation - link the schema article to the error article
- Add description to tags HOT 2
- Field order issue in JSON response HOT 1
- [BUG] Allow specifying field types for custom fields
- [BUG] The other API URLs work, but the openapi docs don't appear. HOT 5
- [BUG] Can't use parameter `keys`
- how to add a description for query params that shows in the generated docs?
- Field with list factory causes API docs to not load with non-serializable. HOT 2
- Annotate Decimal field does not supported "Unable to serialize unknown type: <class 'ellipsis'"
- Traversing the data structures to create an HTTP API client HOT 3
- how to use token ? HOT 1
- Path parameters, order matters HOT 3
- [BUG] Combining JWTAuth with django_auth only works in that order
- [BUG] Pydantic 2.7.0 incompatibily HOT 4
- [BUG] ModelSchema with ManyToManyField won't work under async views HOT 5
- How do you use aliases with nested objects
- [BUG] HOT 1
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 django-ninja.