Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RFC: Propagate unknown value through nested schemas? #980

Closed
lafrech opened this issue Oct 5, 2018 · 7 comments
Closed

RFC: Propagate unknown value through nested schemas? #980

lafrech opened this issue Oct 5, 2018 · 7 comments

Comments

@lafrech
Copy link
Member

lafrech commented Oct 5, 2018

I'm wondering if the unknown value set on parent schema should propagate down through all nested schemas.

We raise by default, and to change that, one needs to let all his schemas specify another behaviour (this is broken but will be fixed when #963 is merged). This can be done with a custom schema to use as a base for all schemas, so it is feasible, and raise is a sensible default IMHO, but wouldn't it make sense to let the parent schema unknown setting propagate?

@vgavro
Copy link
Contributor

vgavro commented Oct 9, 2018

I think it's good idea to add fields.Nested.unknown="inherit", which can be set explicitly, but in most cases what I see you don't want to propagate by default, for example you have http json response, which can have various fields, but if field is nested it will be binded to specific entity, and you want to be sure that fields are strict there, so it's each entity (schema) responsibility to react to unknown fields, not related to parent.
Also (off-topic) I think it will be great to have unknown='warn' or unknown='debug' on schema, i will be glad to create pull request if you think this may be useful.

@RosanneZe
Copy link

It would be nice to have the option to have all nested schemas inherit.

@sloria
Copy link
Member

sloria commented Apr 7, 2019

For now, our stance is that class Meta options should not be automagically propagated to nested fields. Users should use an base schema class in order to share default options across classes.

@sloria sloria closed this as completed Apr 7, 2019
@zaraken
Copy link

zaraken commented Aug 22, 2019

For now, our stance is that class Meta options should not be automatically propagated to nested fields. Users should use an base schema class in order to share default options across classes.

I do agree that class Meta options should not be automatically propagated.

However, what about when overriding unknown in the load method which should according to documentation override the value set at instantiation or in Meta. For this use case it would make sense to (conditionally) allow propagation to nested fields or ?

@charlax
Copy link
Contributor

charlax commented Aug 26, 2019

At the very least, this behavior should be documented.

@mirko
Copy link

mirko commented Nov 25, 2019

I really agree with the previous pro-comments.
I'm using it on load() and it fails for Nested fields, although the doc say:

The unknown option value set in load will override the value applied at instantiation time, which itself will override the value defined in the class Meta.

Which is very much what I'd have expected for nested fields, what the documentation confirms, which however doesn't happen.

Either way: How to solve that? I'm having List() and Item().
I'm sending an instance of a list having items to the server and the server loads and validates sent data via List_Schema().load(unknown=EXCLUDE).
Now an exception is thrown: TypeError: 'X' is an invalid keyword argument for Item

@jemshit
Copy link

jemshit commented Oct 21, 2022

I really agree with the previous pro-comments. I'm using it on load() and it fails for Nested fields, although the doc say:

The unknown option value set in load will override the value applied at instantiation time, which itself will override the value defined in the class Meta.

Which is very much what I'd have expected for nested fields, what the documentation confirms, which however doesn't happen.

Either way: How to solve that? I'm having List() and Item(). I'm sending an instance of a list having items to the server and the server loads and validates sent data via List_Schema().load(unknown=EXCLUDE). Now an exception is thrown: TypeError: 'X' is an invalid keyword argument for Item

So what is the solution for this?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

8 participants