dbrattli/Expression

Option has errors with tuple types when used in a pydantic class

Opened this issue · 0 comments

Describe the bug
If you use an option in pydantic model, but to contain a tuple there are errors. Otherwise its fine
NOT OK => errored_events: Option[t.Tuple[WorkflowEventBase, ...]] = Field()
OK => errored_events: Option[WorkflowEventBase] = Field()

To Reproduce
Steps to reproduce the behavior:
EXAMPLE MODEL

class WorkflowErrorEvent(BaseModel):
  model_config = ConfigDict(arbitrary_types_allowed=True)

  exception: Exception
  run_uuid: UUID

  errored_events: Option[t.Tuple[int, ...]] = Field()
  step_name: Option[str] = Field()
  workflow_name: str = Field()

Expected behavior
A clear and concise description of what you expected to happen.
I'm not sure i undersand why options containing tuples have an issue, but all other types are fine

Code or Screenshots
If applicable, add a minimal code example or screenshots to help explain your problem.


    class WorkflowErrorEvent(BaseModel):
../../.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py:205: in __new__
    complete_model_class(
../../.venv/lib/python3.12/site-packages/pydantic/_internal/_model_construction.py:552: in complete_model_class
    cls.__pydantic_validator__ = create_schema_validator(
../../.venv/lib/python3.12/site-packages/pydantic/plugin/_schema_validator.py:40: in create_schema_validator
    return PluggableSchemaValidator(
../../.venv/lib/python3.12/site-packages/pydantic/plugin/_schema_validator.py:68: in __init__
    self._schema_validator = SchemaValidator(schema, config)
E   pydantic_core._pydantic_core.SchemaError: Error building "definitions" validator:
E     SchemaError: Error building "model" validator:
E     SchemaError: Error building "model-fields" validator:
E     SchemaError: Field "errored_events":
E     SchemaError: Error building "json-or-python" validator:
E     SchemaError: Error building "chain" validator:
E     SchemaError: Error building "function-before" validator:
E     SchemaError: Error building "union" validator:
E     SchemaError: Error building "chain" validator:
E     SchemaError: Error building "is-instance" validator:
E     SchemaError: 'cls' must be valid as the first argument to 'isinstance'

Additional context
Add any other context about the problem here.

  • OS [e.g. Windows]
  • Expression version [e.g 1.0.0]
  • Python version [e.g. 3.10.2]