-
-
Notifications
You must be signed in to change notification settings - Fork 912
RFC: denormalize - do not set null values on not nullable properties #1911
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: denormalize - do not set null values on not nullable properties #1911
Conversation
Should it fail silently? I think it should result in a HTTP 400 status code. |
In my API, I have a |
This is always the same issue (I guess) :p. What if you don't have such constraint? |
Either way, I don't think the normalizer should silently ignore a null value that it cannot set as requested. It should throw an exception. It's then up to the calling code to handle it, and in API Platform we should make sure that it (eventually) becomes a HTTP 400... |
then you'll have a database violation on insert. |
@teohhanhui that seems like a nice solution. |
Issues stays the same when you'd expect a ConstraintValidation instead of a Normalization exception :). And we will not change the listeners order (as discussed in other issues that I'm lazy to look up right now :p). |
either way it needs to be handled somehow. at the moment a |
A 400 should be thrown. Actually, Symfony's We need to figure out why it's not the case. |
https://github.com/bendavies/core/blob/3490493718982044420b98335787f40fabdfb4e6/src/Serializer/AbstractItemNormalizer.php#L230 should already trigger an error :|
|
@dunglas i'll take a look. |
|
|
Mutators should be in sync with the Doctrine mapping. To get the intended behavior I would:
|
ok, sorry the actual problem is for non nullable resources relations, and passing in null.
...
This will trigger a 500, as there is no nullable check here: |
Ok, we should throw in this case. |
thanks, i'll work on this. |
@dunglas what should i be throwing here? Is there currently a handler that converts whichever exception it is to a validation error? |
ahh, |
What's the status on this @bendavies ? |
wow old one...no idea. |
We should throw |
@bendavies Up is this pull request still valid? |
Closing this PR because it's too old and I can't reproduce. |
this will be resolved by symfony/symfony#42502 |
This was discussed a little bit on slack this afternoon.
Should we not call setters with
null
values if the type is not nullable?This seems to be consistent with the check on line 177.
core/src/Serializer/AbstractItemNormalizer.php
Lines 177 to 180 in 592af01
We should respect the property info type
isNullable
value.This is mainly to prevent denormalize errors when an api's resource may have a not nullable setter:
setFoo(string $foo)
but the api request as come in as{"foo": null}
Not sure what the drawbacks are here. I'm sure someone will point something out.
further work if this PR is deemed correct:
The same check should also be done when denormalizing relations.