hug icon indicating copy to clipboard operation
hug copied to clipboard

TypeError: __call__() missing 1 required positional argument: 'context'

Open ptitpoulpe opened this issue 4 years ago • 0 comments

If a validator handler raise a TypeError hug catch it believing (here) that’s is an expected error unexpected keyword argument "context"

A solution is to use replace initialize_handler code with something like that:

import inspect
    def initialize_handler(handler, value, context):
        if "context" in inspect.signature(handler).parameters: # It's better to ask for permission than for forgiveness
            return handler(value, context=context)
        else:
            return handler(value)

ptitpoulpe avatar Jan 19 '21 16:01 ptitpoulpe