I am trying to make a function that takes a pydantic BaseModel
as an input to run another function. I need to unpack the BaseModel into kwargs. I tried doing this:
def run_routing_from_job(job):
return run_routing(
job.inputs.input_file,
**job.inputs.config.dict()
)
where job
is of the format
class Job(BaseModel):
client_info: ClientInfo # Another BaseModel
inputs: RoutingJobInputs # Another BaseModel
uid: UUID = Field(default_factory=uuid4)
status: str = "job_queued"
result: int = None
However, doing .dict()
parses all of the items recursively into a dictionary format. I want to keep the client_info
and inputs
as a BaseModel class, not convert it into a dictionary.
I could make a way to do it, but I can't find a clean way to do it.
job: Job
argument instead of**kwargs
? – Aforejob
instead, but for now I just wanted to unpack the basemodel – Daube