4

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.

Tom McLean
  • 5,583
  • 1
  • 11
  • 36

1 Answers1

1

I worked it out, just replace .dict() with __dict__

def run_routing_from_job(job):
    return run_routing(
        job.inputs.input_file,
        **job.inputs.config.__dict__
    )
Tom McLean
  • 5,583
  • 1
  • 11
  • 36