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

Why error value can be string and list of strings? #210

Closed
andreymal opened this Issue Mar 5, 2016 · 5 comments

Comments

Projects
None yet
3 participants
@andreymal
Copy link

andreymal commented Mar 5, 2016

It is uncomfortable for me. I have to write extra type checking.

This is OK (except #209, but it is not about that):

>>> v = Validator({'name': {'type': 'string', 'minlength': 6, 'regex': '[A-z]+'}})
>>> v.validate({'name': '©'})
False
>>> for field, value in v.errors.items():
...  print(field)
...  for error in value:
...   print(' -', error)
... 
name
 - max length is 6
 - value does not match regex '[A-z]+'

But:

>>> v.validate({'name': 'abc'})
False
>>> for field, value in v.errors.items():
...  print(field)
...  for error in value:
...   print(' -', error)
... 
name
 - m
 - a
 - x
 -  
 - l
 - e
 - n
 - g
 - t
 - h
 -  
 - i
 - s
 -  
 - 6

WAT

I don't wish write if isinstance(value, str)!

@nicolaiarocci

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Mar 6, 2016

This happens on the master branch, right? Should not be on stable (v0.9.2).

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Mar 6, 2016

nah, that's the behaviour how errors are stored in Validator.errors also before 0.10. but it's also implemented in the BasicErrorHandler for backward compatibility.

@andreymal there's also a lower-level access to errros in the master branch: http://docs.python-cerberus.org/en/latest/errors.html

@andreymal

This comment has been minimized.

Copy link

andreymal commented Mar 6, 2016

Lower-level access is too low :)

for backward compatibility.

I only can deal with it and write a custom errorhandler?

@funkyfuture

This comment has been minimized.

Copy link
Member

funkyfuture commented Apr 24, 2016

with a new major relase coming, this behavior could be changed. there shouldn't be an impact on client code unless it could handle single errors on a field anyway.

@nicolaiarocci

This comment has been minimized.

Copy link
Member

nicolaiarocci commented Apr 26, 2016

👍

@nicolaiarocci nicolaiarocci added this to the 1.0 milestone Apr 26, 2016

funkyfuture added a commit to funkyfuture/cerberus that referenced this issue May 12, 2016

streamlines BasicErrorHandler
- error messages are always in a list
- nested errors a kept in the last item if there are any

solves pyeve#210
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment