-
Notifications
You must be signed in to change notification settings - Fork 240
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
readonly param designed behaviour is broken with oneof, anyof #297
Comments
readonly
param designed behaviour is broken with oneof
, anyof
i pledge to mark this for the |
I have performed debug of oneof validation. Schema traversal procedure is correct, but at some point assumption is made that readonly property was already validated in normalization process: def _validate_readonly(self, readonly, field, value):
""" {'type': 'boolean'} """
if not self._is_normalized:
self._error(field, errors.READONLY_FIELD)
# If the document was normalized (and therefore already been
# checked for readonly fields), we still have to return True
# if an error was filed. However, normalization do readonly validation only at first level of schema without traversal at all, rules inside oneof are not inspected and evaluated. def __validate_readonly_fields(self, mapping, schema):
for field in (x for x in schema if x in mapping and
self._resolve_rules_set(schema[x]).get('readonly')):
self._validate_readonly(schema[field]['readonly'], field,
mapping[field]) Link to source called from normalization method Passing Here comes a question, what is right way to fix according to library architecture which I have only partial knowledge about:
|
solving this for one of the rules should solve it for all as the subvalidation dispatching is the same. @dkellner, if i'm not wrong you could be able to give competent guidance on this issue, iirc you implemented the conjunction of normalization and validation for the readonly rule. |
Yes, it was in PR #282. The other (non-simple) fix we had for that is in #272, and I still have the branch here: https://github.com/dkellner/cerberus/tree/default-readonly . IIRC and Cerberus still works the same internally, we're doing two full traversals now: one for normalization, and one for validation (more details in e.g. #268 (comment)). Unfortunately I cannot look deeper into this now as lunar new year is coming. Let me know if I can still be of help in about two weeks. |
and i want to point out that the two traversals are different and that itches me because it complicates things, but there seems no sane way around it. anyway, has someone the time to tackle this bug? it's the hardest nut on the 1.3 playlist so far. |
I'm afraid I will not find the time for that the coming weeks. There are still some "urgent" issues in Eve-SQLAlchemy I'd have to tackle first and that's progressing rather slowly already...
I'd argue the very nature of normalization and validation are different. If we're not doing a clear separation we will run in all kind of interesting bugs as the document keeps changing at a stage (validation) we're not expecting that anymore. And with |
that is more or less my point. the thing is, the code is very prone to bugs, though the processing stages are seperated clearly and because the user interface happens to expose rules and interdependencies of such across the stages. but we wouldn't want to change the simplicity of the interface that is provided by this. i just feel the urge to re-iterate often enough that each design decision and implementation detail that touches these circumstances must be well reasoned and that it all has its limits. the |
before i leave town for a while i'd like to share some thought i had when zooming out on this issue. i noticed a contradiction that hadn't been formulated yet: the first statement is that we do not consider normalization rules as valid in the so, i'd like to take these two options into consideration:
@rredkovich, regarding your concrete use-case: why don't you define rules for the |
unless there are other proposals how to proceed with this issue, i'm going to remove the |
Use-case abstract
According to docs
readonly
parameter should give False on validation if field with that parameter is in dict.Works as expected in general case:
Support request / Bug report
However using multiple schemas with
oneof
for field will produce unexpectedTrue
.anyof
gives same result, not tested withnoneof
andallof
.Bug exists in version 1.1, 1.0.x, in 9.x exception is raised when using
readonly
param.The text was updated successfully, but these errors were encountered: