-
-
Notifications
You must be signed in to change notification settings - Fork 131
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
Strategy for dealing with invalid data #1481
Comments
Here is my proposal:
what do you think about this proposal ? |
That's a wrong assumption. Let's take the
The current code uses Unless I missed something, the cases you describe in this issue might occur only when the server returns invalid data. When we started working on AsyncAws we decided to trust the provider. |
Please read the ticket again. I'm explicitly saying that this applies to ValueObject and Result classes. CreateBucketRequest is an Input class. |
Well, as explained here, you only trust it partially (as you still try to deal with missing array keys for invalid fields. |
Do you have an example? As far as I can see
For ValueObject I don't remember which strategy is used given object might be used either in request (user are allowed to temporary enter null value) and response (we trust the provider and now the data will be populated with the correct value) |
For the existence check of required fields, this is indeed something done in ValueObject only, not in Result.
this is not true actually. Value objects are immutable. They don't have any setter. So if they fill in invalid data, they have no opportunity to fix that later. |
indeed. When the object is used in INPUT:
|
@jderusse the performance overhead will not be bigger than the current about making the getter nullable, this would be a huge pain for usage in response (as static analysis tools will tell you that the value is possibly null and you need to handle it). and there are objects used in both input and response. So I'm in favor of adding an early check (I can do the PR). |
works for me. Thank. Would it fix the issue with |
The issue for for timestamp, I will check what is the easiest way to handle those |
Currently, the way invalid data is handled in value objects and results is quite messy:
null
, which will then throw a TypeError when calling the getterfalse
to the property, which also leads to a TypeError when calling the getternull
to the property, which means it removes the datefalse
to the property (which also leads to a TypeError when calling the getter)Additionally, for JSON response parsers, we use
filter_var(..., FILTER_VALIDATE_BOOLEAN)
, which means we first cast the boolean value from the json to string before validating it again. This is quite inefficient way to ensure we have a boolean in the property.This inconsistency between the expected property type and the assigned value gets caught by static analysis tools in #1467 once I actually define the expected property type in phpdoc.
Note: input objects are already clean in that regard. They define all fields as nullable in a consistent way (getters are also nullable) and validate things when creating the request body.
What should be the strategy to handle those values ?
The text was updated successfully, but these errors were encountered: