Skip to content
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

Usage of allowed and nullable params #454

Closed
mishgu opened this issue Nov 6, 2018 · 5 comments

Comments

Projects
None yet
3 participants
@mishgu
Copy link

commented Nov 6, 2018

I'm have a issues when use allowed and nullable params

Use-case abstract

 schemas = [
    {'role': {'type': 'string', 'allowed': ['agent', 'client', 'supplier']}},
    {'role': {'type': 'string', 'allowed': ['agent', 'client', 'supplier', None]}},
    {'role': {'type': 'string', 'allowed': ['agent', 'client', 'supplier'], 'nullable': True}},
    {'role': {'type': 'string', 'allowed': ['agent', 'client', 'supplier', None], 'nullable': True}},
    {'role': {'type': 'string', 'nullable': True}},
]
data = [
    {'role': 'agent'},
    {'role': None},
]

Output from cerberus

Version - 1.2
Schema # 	   Data
   1		True  False  
   2		True  False  
   3		True  False  
   4		True  True  
   5		True  True  

Version - 1.1
Schema # 	   Data
   1		True  False  
   2		True  False  
   3		True  True  
   4		True  True  
   5		True  True  

Bug report / Feature request

As we can see in v1.2 have different ouput with nullable param (3td schema). It looks like a bug
In my oppinion v1.1 working more properly

@funkyfuture

This comment has been minimized.

Copy link
Member

commented Nov 6, 2018

see also #393 and #400. it would be helpful if you researched with git bisect which commit changed the behaviour. would you prefer that a positively defined nullable implies None to be included in allowed's constraints?

@funkyfuture funkyfuture added this to the 1.2.1 milestone Jan 14, 2019

@cpforbes

This comment has been minimized.

Copy link

commented Jan 17, 2019

It looks like 74c015b introduced the change.

It seems that allowed needs to be added the the call to _drop_remaining_rules in order to match the 1.1 behavior.

@cpforbes

This comment has been minimized.

Copy link

commented Jan 18, 2019

This appears to be related to #373

@cpforbes

This comment has been minimized.

Copy link

commented Jan 18, 2019

After looking at the old code a bit more it seems that previously all other rules were skipped after the nullable rule if the field was null.

for rule in prior_rules:
if validate_rule(rule):
return

@funkyfuture

This comment has been minimized.

Copy link
Member

commented Jan 18, 2019

no, on the contrary, no rules were skipped at all some rules caused remaining rules to be dropped, others didn't.

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue Jan 27, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.