Closed
Labels
Description
Apache Airflow Provider(s)
standard
Versions of Apache Airflow Providers
apache-airflow-providers-standard==1.1.0
Apache Airflow version
2.10.5, 2.11.0
Operating System
Airflow docker
Deployment
Other Docker-based deployment
Deployment details
Airflow base docker image with minor customisations on EKS
What happened
When upgrading airflow-providers-standard to from 1.0.0 to 1.1.0 or 1.2.0 we receive the following failure + stacktrace at runtime
[2025-05-21, 16:35:42 BST] {taskinstance.py:3313} ERROR - Task failed with exception
Traceback (most recent call last):
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py", line 768, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/taskinstance.py", line 734, in _execute_callable
return ExecutionCallableRunner(
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/utils/operator_helpers.py", line 252, in run
return self.func(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/models/baseoperator.py", line 424, in wrapper
return func(self, *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/branch.py", line 105, in execute
return self.do_branch(context, self.choose_branch(context))
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/latest_only.py", line 69, in choose_branch
dates = self._get_compare_dates(dag_run)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/providers/standard/operators/latest_only.py", line 110, in _get_compare_dates
if prev_info := self.dag.timetable.next_dagrun_info(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/interval.py", line 105, in next_dagrun_info
align_last_data_interval_end = self._align_to_prev(last_automated_data_interval.end)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/_cron.py", line 145, in _align_to_prev
prev_time = self._get_prev(current)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/airflow/.local/lib/python3.12/site-packages/airflow/timetables/_cron.py", line 124, in _get_prev
return convert_to_utc(current.in_timezone(self._timezone) - delta)
^^^^^^^^^^^^^^^^^^^
AttributeError: 'datetime.datetime' object has no attribute 'in_timezone'. Did you mean: 'astimezone'?
The dag definition has the following parameters:
{
"start_date": datetime(2019, 9, 1),
"retries": 2,
"retry_delay": timedelta(minutes=5),
"catchup": False,
"max_active_tasks": 1,
"default_args": default_args,
"max_active_runs": 1,
"schedule": "@hourly",
"tags": [
"analytics-ingest",
"postgres-ingest",
*dag_options.get("tags", []),
],
},
What you think should happen instead
No error should occur
How to reproduce
Due to the simplicity of the DAG I'm inclined to say this occurs on any airflow 2.10.5/2.11.0 installation using airflow-providers-standard==1.2.0 where schedule="@hourly" and LatestOnlyOperator is used,
e.g.
from airflow.providers.standard.operators.latest_only import LatestOnlyOperator
LatestOnlyOperator(task_id="only_run_latest_execution")
Anything else
No response
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Activity
leakec commentedon May 22, 2025
I'm experiencing the same issue in 3.0.1.
In
airflow/providers/standard/operators/latest_only.pynear line 102 I seeI think the
dag_run.data_interval_startanddag_run.data_interval_endmay bedatetimeobjects (from thedatetimepackage) rather thanpendulum.DateTimeobjects, which could be leading to this error.leakec commentedon May 22, 2025
Converting these lines to a
pendulum.instanceas shown below fixed the issue for me:leakec commentedon May 22, 2025
I tried to re-create this by adding a test in
airflow/providers/standard/tests/unit/standard/operators/test_latest_only_operator.pylikebut I could not trigger the same error. For some reason in this case the value is passed as an actual
DateTimerather than adatetime. I think this is likely something I'm doing incorrectly in setting up the test case, but I don't know enough about how airflow testing works to figure out what, if anything, is different.I do know that this needs to occur when a schedule is a cron trigger running every hour to make it to the portion of
_cron.pythat tries to callin_timezoneon the incoming value. However, for some reason in the test case it has the proper type ofDateTime.I'm hoping someone with more knowledge of airflow testing can pick up where I left off, or help me fix any mistakes I have made.
EDIT: I've tried the cron trigger as "0 * * * * " and " * * * * *", but neither seems to error the test out.
leakec commentedon Jul 15, 2025
Stepped up to airflow 3.0.3 and airflow-providers-standard 1.4.0, but this is still an issue for me.
potiuk commentedon Jul 15, 2025
Which means? What is your problem in detail? can you describe it and provide YOUR stack traces with those versions? That halps anyne who tries to analyse the issue in their free time to do it as efficiently as possible, and it's actually about a million times more helpful than adding a comment "I have the same problem"
leakec commentedon Jul 15, 2025
@potiuk My apologies, you're right, I should have included them. Here is what I'm seeing in airflow. I've stripped out absolute paths so they are relative to the airflow installed directory.
EDIT: Edited stack trace above to reflect the test dag shown down below.
It's also worth noting I fixed this locally using the same fix I mentioned above. I would be happy to make a PR for this, but I got stuck on re-creating the issue in testing (see my comment above). If you have any suggestions there, I'd be happy to try them. Thanks!
potiuk commentedon Jul 16, 2025
I guess then that might be somethig @uranusjr might be best to answer. If that clearly reproducible in latest version of airflow - I marked it as "affected_version:3.0"
leakec commentedon Jul 17, 2025
For anyone looking to reproduce the problem, a simple way to do so is run the following DAG in an airflow instance:
gopidesupavan commentedon Jul 18, 2025
am able to reproduce this, i think the error seems to happen only when there is cron expression provided, likely _get_next getting datatime.datetime type , instead of pendulum.DateTime. IMO its better to update this function to convert pendulum the current function arg value.
airflow/airflow-core/src/airflow/timetables/_cron.py
Line 106 in 4eb776a
gopidesupavan commentedon Jul 18, 2025
@leakec would like to open PR ?
2 remaining items
Fixing latest_only_operator. See apache#50911
Making an attempt at a reg test. However, this does not reproduce the…
leakec commentedon Jul 19, 2025
@gopidesupavan Sweet, will do. I looked into modifying the
_get_nextfunction today rather than the one I originally mentioned. However, everything looks good in this function provided that aDateTimeis passed in, and similarly up the stack trace.I think the real issue is in the original spot I mentioned. The
DataIntervalis typed to take aDateTimeinstance for both arguments, butdag_run.data_interval_startanddag_run.data_interval_endaredatetimeinstances. Based on the type hints given in the functions, everything looks right all the way up the stack trace except this spot.I could change the
_cron_get_nextfunction, but if I do, I feel the correct thing would be to change the typing to bedatetime | DateTimeand that would percolate a lot of changes to type hints throughout. Since these methods are designed to take aDateTimeinstance, I think the correct thing to do is just modifylatest_onlywhere we are passing the incorrect type.If you feel strongly that
_get_nextand_get_prevshould be changed to takeDateTime | datetimewith a conversion topendulum.instancefor anydatetimepassed in, I can make the changes, but this will take me much longer, as I should look at the functions that call them.I've made the PR at #53541 with the fix I originally proposed, but like I said, happy to make the change directly to
_cronif you feel those functions really should take adatetimeorDateTimeas the argument.gopidesupavan commentedon Jul 22, 2025
thanks will look into, was off sick last two days.
leakec commentedon Jul 22, 2025
No worries and no rush. Sorry to hear you were sick. Hope you're feeling better now!
fix: Type mismatch for DateInterval in latest only operator (#53541)
gopidesupavan commentedon Jul 25, 2025
good thanks for asking :)
fix: Type mismatch for DateInterval in latest only operator (#53541)
fix: Type mismatch for DateInterval in latest only operator (#53541)
fix: Type mismatch for DateInterval in latest only operator (#53541)
fix: Type mismatch for DateInterval in latest only operator (#53541)
fix: Type mismatch for DateInterval in latest only operator (#53541)