cerberus icon indicating copy to clipboard operation
cerberus copied to clipboard

Default setter needs to know the field name

Open pvanderlinden opened this issue 9 years ago • 3 comments

It would be very usefull to let the default setter know which field it is. Use case:

  • a filter can only have values which depends on the logged in user
  • if the filter is missing it should default to all the values the user is allowed to pass in

Currently I work around this issue by having the default setter set it to '__all__' and then in the custom validator (which also validates the allowed values), and let it expand to actual default in self.document. Which might break in feature versions.

pvanderlinden avatar Nov 03 '16 18:11 pvanderlinden

Since the field was mandatory in my custom _validate_type_string and _validate_type_date functions, i modify the validator class too. Please leave the field name in the parameters or set a way to get the current processed field name from the Validator class

marcpearson avatar Mar 05 '17 20:03 marcpearson

what about the following design: the callables' signatures are inspected before calling and provided with the parameters as needed. like pytest is injecting fixtures to test functionns.

funkyfuture avatar Apr 16 '17 11:04 funkyfuture

so, the idea of dependency injection that allows custom signatures is included in the roadmap for the next major release. it will take a while 'til the journey gets there, and this feature has a rather high potential to conflict with the desire to not break too much with a major release.

funkyfuture avatar Jun 02 '18 12:06 funkyfuture