Fix type of "moment" when running an e2e example for deferred TI#45030
Merged
kaxil merged 4 commits intoapache:mainfrom Dec 18, 2024
Merged
Fix type of "moment" when running an e2e example for deferred TI#45030kaxil merged 4 commits intoapache:mainfrom
kaxil merged 4 commits intoapache:mainfrom
Conversation
amoghrajesh
commented
Dec 18, 2024
kaxil
reviewed
Dec 18, 2024
ashb
reviewed
Dec 18, 2024
ashb
reviewed
Dec 18, 2024
Contributor
Author
|
Simplifies it better now. This is a working example: |
ashb
approved these changes
Dec 18, 2024
got686-yandex
pushed a commit
to got686-yandex/airflow
that referenced
this pull request
Jan 30, 2025
…che#45030) While trying to run an e2e example of a task that defers and then launches a trigger: ``` from airflow import DAG from airflow.providers.standard.sensors.date_time import DateTimeSensorAsync from airflow.utils import timezone import datetime with DAG( dag_id="demo_deferred", schedule=None, catchup=False, ) as dag: DateTimeSensorAsync( task_id="async", target_time=str(timezone.utcnow() + datetime.timedelta(seconds=3)), poke_interval=60, timeout=600, ) ``` I realised that the "moment" inside "trigger_kwargs" is of `pendulum.DateTime` type, and since we have a "dict[str, ANY]`, defined here: https://github.com/apache/airflow/blob/main/airflow/api_fastapi/execution_api/datamodels/taskinstance.py#L82 on its datamodel (we cant really have a `UtcDateTime` for one specific field, like we do [here](https://github.com/apache/airflow/blob/main/airflow/api_fastapi/execution_api/datamodels/taskinstance.py#L57C15-L57C26)), it fails to match the type defined in the `Trigger` table which is datetime. So, I have added a "before" validator that checks for the type being string and if it is a string, translates it to a datetime object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
While trying to run an e2e example of a task that defers and then launches a trigger:
I realised that the "moment" inside "trigger_kwargs" is of
pendulum.DateTimetype, and since we have a "dict[str, ANY]`, defined here: https://github.com/apache/airflow/blob/main/airflow/api_fastapi/execution_api/datamodels/taskinstance.py#L82on its datamodel (we cant really have a
UtcDateTimefor one specific field, like we do here), it fails to match the type defined in theTriggertable which is datetime.So, I have added a "before" validator that checks for the type being string and if it is a string, translates it to a datetime object.
^ Add meaningful description above
Read the Pull Request Guidelines for more information.
In case of fundamental code changes, an Airflow Improvement Proposal (AIP) is needed.
In case of a new dependency, check compliance with the ASF 3rd Party License Policy.
In case of backwards incompatible changes please leave a note in a newsfragment file, named
{pr_number}.significant.rstor{issue_number}.significant.rst, in newsfragments.