I'm using Pydantic's BaseModel for creating my working class. I also have custom methods other than the methods with validators. I need to use singledispatchmethod decorator from functools with the custom function. For example,
class Foo(pydantic.BaseModel):
name: str
bar: int
baz: int
@functools.singledispatchmethod
def handle(self, command: Command) -> CommandResult:
pass
@celery.task
def add(a: int, b: int):
time.sleep(10)
print("Sum is: ", a+b)
However, it's throwing the following error for using the singledispatchmethod
File "/models.py", line 56, in <module>
class Foo(pydantic.BaseModel):
File "pydantic/main.py", line 323, in pydantic.main.ModelMetaclass.__new__
File "pydantic/fields.py", line 411, in pydantic.fields.ModelField.infer
File "pydantic/fields.py", line 342, in pydantic.fields.ModelField.__init__
File "pydantic/fields.py", line 456, in pydantic.fields.ModelField.prepare
File "pydantic/fields.py", line 670, in pydantic.fields.ModelField.populate_validators
File "pydantic/validators.py", line 715, in find_validators
RuntimeError: no validator found for <class 'functools.singledispatchmethod'>, see `arbitrary_types_allowed` in Config
In the same fashion I also want to use Celery's task decorator on one such custom methods.