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

Rename and Coerce do not work together #607

Open
aaron11496 opened this issue Aug 15, 2023 · 2 comments
Open

Rename and Coerce do not work together #607

aaron11496 opened this issue Aug 15, 2023 · 2 comments

Comments

@aaron11496
Copy link

>>> import cerberus
>>> cerberus.__version__
'1.3.4'
>>> from cerberus.validator import Validator
>>> Validator().normalized({'f': '123'}, schema={'f': {'type': 'integer', 'coerce': int}})
{'f': 123}
>>> Validator().normalized({'f': '123'}, schema={'f': {'type': 'integer', 'coerce': int, 'rename': 'g'}})
{'g': '123'}

I would expect the coerce to still take effect here. Please let me know whether this is intended behavior or if there is another way to do what I intended.

@funkyfuture
Copy link
Member

funkyfuture commented Oct 23, 2023

yes, it is a known issue that people walk into by intuition. be aware that validation rules are validated against the normalized document.

i keep this issue open as a reminder that admonitions that point people to the proper considerations should be added to the docs about schemas and normalization rules. also, the former should be renamed to just "Schemas". other documents and docstrings also still state "validation schemas" (sometimes joined w/ a dash) though they are meant generally.

@aeoluszzff
Copy link

aeoluszzff commented Oct 28, 2023

also rename and default don't work together

>>>from cerberus import Validator
>>>v = Validator({'foo': {'default': '1', 'rename': 'bar'}})
>>>print(v.normalized({'foo': 2}))
{'bar': 2, 'foo': '1'}
#expect result
{'bar': 2}

i think rename should process at last in function __normalize_mapping

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants