Dependency doesn't play well with required#665
Conversation
|
That's actually how it is supposed to work right now. If a required field also has dependencies and it is missing, then we only report it as missing if the dependencies there. |
|
In my case the dependency is met thru the default value of the depending field but still doesn’t complain if the required field is omitted. I can change the test to meet that case if you want. Also I think that when you use required, you expect that whatever the other directives, you won’t end up with a missing field in the db. |
it used to be like this. New behaviour was introduced with pyeve/cerberus/pull/61 by @hthieu1110. This test in particular shows that this is in fact the intended behaviour. Now, I agree that this is somewhat convoluted. I'd appreciate if @hthieu1110, as the original patch author, would chime in on this one. |
'required' is always evaluated, independent of eventual missing dependenies. This changes the previous behaviour whereas a required field with dependencies would only be reported as missing if all dependencies were met. A missing required field will always be reported. Addresses nicolaiarocci/eve#665.
'required' is always evaluated, independent of eventual missing dependencies. This changes the previous behaviour whereas a required field with dependencies would only be reported as missing if all dependencies were met. A missing required field will always be reported. Addresses nicolaiarocci/eve#665.
|
Sorry to jump in so late, just starting to use Eve. But then how could I require a field only if another field is of value X? I got a field "mytype" with 2 possible value A and B, I want that when "mytype" is A only, then field "myfield" is required. I did that with a dependency set on the field "myfield" that need "mytype" to be A. But this patch broke that logic. Any workaround ? Thanks! |
If a field has both a dependency and a required directive, the required directive is just ignored. This PR contains a failing test to demonstrate the issue.