-
Notifications
You must be signed in to change notification settings - Fork 349
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
Add flag to skip property verification in ODataResource
#2812
Add flag to skip property verification in ODataResource
#2812
Conversation
This PR has Quantification details
Why proper sizing of changes matters
Optimal pull request sizes drive a better predictable PR flow as they strike a
What can I do to optimize my changes
How to interpret the change counts in git diff output
Was this comment helpful? 👍 :ok_hand: :thumbsdown: (Email) |
/// before setting the <see cref="Properties"/> property. This can be a useful optimization | ||
/// in hot paths when you're sure property values are valid. | ||
/// </summary> | ||
public bool SkipPropertyVerification { get; set; } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't this be better as a global setting (e.g. ODataMessageWriterSettings
/ODataMessageReaderSettings
) instead of a property that has to be set on each ODataResource
instance?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Problem is ODataResource
doesn't have access to the message writer settings.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe the serializer that creates ODataResources could use the ODataMessageWritter
settings to decide whether to set the skip verification flag, but in that case it would still have to set it for every resource.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"it would still have to set it for every resource" - Why would it need to be set for every resource? Why can't the serializer control whether the property verification methods should be called? I don't think it's any of the ODataResource
methods that calls methods for verifying or writing the properties. It's the serializer that does so... If it has access to the settings, it can control whether to skip verification or not.
A different question, by which means did you envision that the SkipPropertyVerification
would be set?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I agree with @gathogojr
Can we use the same setup as the IDuplicatePropertyNameChecker
where the serializer have access to the ODataMessageWriteSettings
and this set in the WriterValidator
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it's any of the ODataResource methods that calls methods for verifying or writing the properties. It's the serializer that does so... If
In the existing code, it is actually the ODataResource
that calls the method for verifying properties, it happens inside the ODataResourceBase.Properties
setter. That's why I applied the flag to the ODataResource
.
Each ODataResource
instance is independent, and the ODataMessageWriter
operates on a resource-per-resource basis. The ODataMessageWriter
does not know about the serializer.
@KenitoInc does have access to the the ODataMessageWriterSettings
but the ODataResource
does not. Currently the verification happens within the ODataResource
itself, not the serializer nor the message writer.
We could change things up such that the verification is moved out of the ODataResource
and moved into the message writer. Or we could remove the verification altogether and let the serializer handle that manually if it deems fit. I'm not sure if this delayed verification would have unintended consequences in those where verification is desired.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
To make a correction, the verification ensures that the property values are not ODataResourceValue instances. Apparently ODataResourceValue is different from ODataResource. An ODataResourceValue is an ODataValue that has nested properties, so basically still a nested resource. It's intended for use in instance annotations that have complex values.
I tried to create an ODataResource which nested ODataResourceValues in its properties after disabling verification, and it got serialized without error. This means that the writer does not validate against this. So, if we remove the validation from within ODataResource and want to retain the existing behaviour, then we'd need to perform this verification in the writer or ask the caller to handle it on their own.
Issues
This pull request fixes #2803
Description
This PR adds a
SkipPropertyVerification
property toODataResource
which skips property verification. By default,ODataResource
will verify the property values when theProperties
property is set. The aim of the of the verification is to ensure that propertiesODataResourceValue
s are not included in the properties. I.e. the property values should either primitive types or collections of primitive types (ODataResourceValue
is intended for use in annotations).However, in scenarios like AspNetCoreOData, where the library already creates
ODataResource
that already match this expectation, it's an unnecessary cost to still go ahead and perform this verification. This flag can be used in AspNetCoreOData to avoid paying this cost for every resource that is created.Checklist (Uncheck if it is not completed)