readonly param designed behaviour is broken with oneof, anyof
See original GitHub issueUse-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:
import cerberus
schema_one = {
'id': {'type': 'integer', 'readonly': True},
'text': {'type': 'string', 'required': True}
}
schema_two = {
'id': {'type': 'integer', 'readonly': True},
'extra_text': {'type': 'string', 'required': True}
}
v = cerberus.Validator({'record': {'type': 'dict', 'schema': schema_one}})
test_data = {'record': {'id': 10, 'text': 'ooops'}}
v.validate(test_data)
# -> False
v.errors
# -> {'record': [{'id': ['field is read-only']}]}
Support request / Bug report
However using multiple schemas with oneof
for field will produce unexpected True
.
import cerberus
schema_one = {
'id': {'type': 'integer', 'readonly': True},
'text': {'type': 'string', 'required': True}
}
schema_two = {
'id': {'type': 'integer', 'readonly': True},
'extra_text': {'type': 'string', 'required': True}
}
v = cerberus.Validator({'record': {'type': 'dict', 'oneof_schema': [schema_one, schema_two]}})
test_data = {'record': {'id': 10, 'text': 'ooops'}}
v.validate(test_data)
# -> True
v.errors
# -> {}
anyof
gives same result, not tested with noneof
and allof
.
Bug exists in version 1.1, 1.0.x, in 9.x exception is raised when using readonly
param.
Issue Analytics
- State:
- Created 7 years ago
- Comments:9 (9 by maintainers)
Top Results From Across the Web
readOnly does not work together with polymorphic oneOf. #400
Describe the bug readOnly does not work together with polymorphic oneOf. To Reproduce Use this spec: openapi: 3.0.0 info: title: Dummy API description: ......
Read more >Understanding JSON Schema
JSON Schema is a powerful tool for validating the structure of JSON data. However, learning to use it by reading its.
Read more >If functions have to do null checks before doing the intended ...
@aroth your code is broken because its passing my code a null when it should be passing something that has Name as a...
Read more >Add to TelerikTextBox more parameters, such as
Add to TelerikTextBox more parameters, such as: Type, Autocomplete, Required, ReadOnly. Type needed for Password set. Duplicated Items.
Read more >Using failover in an Amazon Aurora global database
Managed planned failover is designed to be used on a healthy Aurora global ... The chosen secondary cluster promotes one of its read-only...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
unless there are other proposals how to proceed with this issue, i’m going to remove the
1.3
milestone from this.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. https://github.com/pyeve/cerberus/issues/268#issuecomment-248239479).
readonly
is special in that: it’s a validation rule that needs to be performed before normalization because it should see the original document before any modifcation happened. Unfortunately you cannot easily traverse the document for justreadonly
(that is exactly why I’ve implemented therule_filter
in #272).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.