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

if a default_setter has a field argument pass the field name to that … #314

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion cerberus/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -785,12 +785,17 @@ def _normalize_default_setter(self, mapping, schema, field):
{'type': 'callable'},
{'type': 'string'}
]} """
import inspect
if 'default_setter' in schema[field]:
setter = schema[field]['default_setter']
if isinstance(setter, _str_type):
setter = self.__get_rule_handler('normalize_default_setter',
setter)
mapping[field] = setter(mapping)
argspec = inspect.getfullargspec(setter)
if 'field' in argspec.args or 'field' in argspec.kwonlyargs:
mapping[field] = setter(mapping, field=field)
else:
mapping[field] = setter(mapping)

# # Validating

Expand Down