There are many solutions available to overwrite methods on instances. But for an object of the pydantic BaseModel this seems to be problematic. This is a simple example:
from pydantic import BaseModel
class Dog(BaseModel):
def bark(self):
print("WOOF")
def new_bark():
print("WoOoOoF!!")
Running the method:
>>> boby = Dog()
>>> boby.bark()
WOOF
Overwriting the method:
>>> boby.bark = new_bark
>>> boby.bark()
ValueError: "Dog" object has no field "bark"
The expected result would be a printed # WoOoOoF!!. If Dog does not inherit pydantics BaseModel you get the expected result.
Is this even possible?