question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

readonly param designed behaviour is broken with oneof, anyof

See original GitHub issue

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:

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:open
  • Created 7 years ago
  • Comments:9 (9 by maintainers)

github_iconTop GitHub Comments

1reaction
funkyfuturecommented, Jul 5, 2018

unless there are other proposals how to proceed with this issue, i’m going to remove the 1.3 milestone from this.

1reaction
dkellnercommented, Feb 14, 2018

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 just readonly (that is exactly why I’ve implemented the rule_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.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found