pierrejeambrun commented on code in PR #48239:
URL: https://github.com/apache/airflow/pull/48239#discussion_r2012214396
##########
airflow-core/src/airflow/jobs/triggerer_job_runner.py:
##########
@@ -192,9 +202,22 @@ class TriggerStateChanges(BaseModel):
finished: list[int] | None = None
+def get_discriminator_value(v: Any) -> Any:
+ if isinstance(v, dict):
+ return v.get("kind", v.get("type"))
+ return getattr(v, "kind", getattr(v, "type", None))
+
+
ToTriggerRunner = Annotated[
- Union[workloads.RunTrigger, messages.CancelTriggers,
messages.StartTriggerer],
- Field(discriminator="kind"),
+ Union[
+ Annotated[workloads.RunTrigger, Tag("RunTrigger")],
+ Annotated[messages.CancelTriggers, Tag("CancelTriggersMessage")],
+ Annotated[messages.StartTriggerer, Tag("StartTriggerer")],
+ Annotated[ConnectionResult, Tag("ConnectionResult")],
+ Annotated[VariableResult, Tag("VariableResult")],
+ Annotated[ErrorResponse, Tag("ErrorResponse")],
+ ],
+ Field(discriminator=Discriminator(get_discriminator_value)),
Review Comment:
This is what I wanted to do originally, but I realized that `RunTrigger`,
`CancelTriggers` and `StartTriggerer` do not have 'type' but 'kind', this is
why I'm building a custom discriminator that will try `kind` and fallback to
`type` if it does not find a value there. (Or maybe you have something else in
mind?)
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]