Problem with required and dependencies
See original GitHub issueUsed Cerberus version 1.0.1 installed with pip
- I consulted these documentations:
- [ Validation Rules] http://docs.python-cerberus.org/en/stable/validation-rules.html
Support request / Bug report
According to the docs, the following program should validate successfully since
the auth-key
field is required only when the auth
field is wep
or wpa
.
import cerberus
schema = {
'auth' : {
'type':'string',
'required':True,
'allowed':['open','wep','wpa']
},
'auth-key' : {
'type':'string',
'required':True,
'dependencies': {'auth': ['wep', 'wpa']}
}
}
v = cerberus.Validator(schema)
print v.validate({'auth':'open'})
print v.errors
The output of the program is the following:
False
{'auth-key': ['required field']}
Is this a bug ?
Issue Analytics
- State:
- Created 7 years ago
- Reactions:1
- Comments:16 (3 by maintainers)
Top Results From Across the Web
Valorant: How to fix the 'Required Dependencies' error
First and foremost, the Required Dependencies error is one that stems from the device itself, and it essentially prevents the Riot Games ......
Read more >Easily Fix Valorant We Couldn't Install a Required Dependency
This post introduces 2 simple ways to help you solve the “Valorant we couldn't install a required dependency” issue. You can try them....
Read more >Valorant: How To Fix Required Dependencies Error (2022)
Here's how to fix Required Dependencies Error in Valorant. Get all solutions for the "We couldn't install a required dependency issue."
Read more >Dependency hell - Wikipedia
The dependency issue arises when several packages have dependencies on the same shared packages or libraries, but they depend on different and incompatible ......
Read more >How to Install and Correct Dependencies Issues in Ubuntu
First, we would need to install a libpython2.7-minimal package/dependency. We can run this command to accomplish this. root@host:~# apt-get ...
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
I’ll add my two cents since I’m the one who opened the issue. I think that obvious things should just work, without complicated hacks that make the rules obscure and hard to understand. Before opening this issue i’ve read the docs many times and spent almost an hour trying to understand why it didn’t work. In the end I realized that I was fighting against the library instead of using it to solve my problem, so I gave up and coded the validation logic by hand.
To avoid confusion I’ll post here the relevant lines extracted from the documentation of the “required” validation option:
I am no english expert… but what I think when I see this phrase in the docs is that a required field is NOT required if the dependencies of that field are missing. In other words, I’m not required to tell you my wireless password if I’m going with open authentication.
I think that such a rule is actually very common in validation, so common that it should be pretty straightforward to implement and work out of the box without obscure hacks.
From what I see here there is either a false statement in the docs or a bug in the code. If fixing the code is not possible due to backwards compatibility then fix the docs.
IMHO, adding some weird non-intuitive rules to make it work is a bad idea.
I don’t think it’s a bug. You need to be more precise when specifying the auth-key:
It’s like saying: “wether auth-key is defined or auth is ‘open’”.