You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by "dwreeves (via GitHub)" <gi...@apache.org> on 2024/03/20 17:27:35 UTC
[I] `DateTimeSensor()` does not work with `datetime`s rendered via `render_template_as_native_obj=True` [airflow]
dwreeves opened a new issue, #38336:
URL: https://github.com/apache/airflow/issues/38336
### Apache Airflow version
2.8.3
### If "Other Airflow 2 version" selected, which one?
_No response_
### What happened?
Running the following code produces an error:
```python
with DAG(
dag_id="test_date_time_sensor",
schedule="@monthly",
start_date=datetime(2024, 1, 1),
render_template_as_native_obj=True
) as dag:
wait = DateTimeSensorAsync(
task_id="wait",
target_time="{{ (data_interval_end + macros.timedelta(minutes=1)) }}"
)
```
Here's the full traceback:
```
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 444, in _execute_task
result = _execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/models/taskinstance.py", line 414, in _execute_callable
return execute_callable(context=context, **execute_callable_kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/sensors/date_time.py", line 94, in execute
trigger = DateTimeTrigger(moment=timezone.parse(self.target_time))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/airflow/utils/timezone.py", line 213, in parse
return pendulum.parse(string, tz=timezone or TIMEZONE, strict=strict) # type: ignore
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pendulum/parser.py", line 30, in parse
return _parse(text, **options)
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pendulum/parser.py", line 43, in _parse
parsed = base_parse(text, **options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 78, in parse
return _normalize(_parse(text, **_options), **_options)
^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/pendulum/parsing/__init__.py", line 113, in _parse
return parse_iso8601(text)
^^^^^^^^^^^^^^^^^^^
TypeError: argument 'input': 'DateTime' object cannot be converted to 'PyString'
```
The way to fix it is to add a `| string` filter to the Jinja:
```python
target_time="{{ (data_interval_end + macros.timedelta(minutes=1)) | string }}"
```
### What you think should happen instead?
The operator should handle typing for the timestamp in `execute()` instead of in `__init__`, so that runtime conversions can be properly handled.
### How to reproduce
See code example above.
### Operating System
Not relevant
### Versions of Apache Airflow Providers
_No response_
### Deployment
Other
### Deployment details
Deployment is not relevant.
### Anything else?
This can also probably be removed this the code for `DateTimeSensorAsync` while I/we are at it:
```python
def __init__(self, **kwargs) -> None:
super().__init__(**kwargs)
```
### Are you willing to submit PR?
- [X] Yes I am willing to submit a PR!
### Code of Conduct
- [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md)
--
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: commits-unsubscribe@airflow.apache.org.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] `DateTimeSensor()` does not work with `datetime`s rendered via `render_template_as_native_obj=True` [airflow]
Posted by "Lee-W (via GitHub)" <gi...@apache.org>.
Lee-W closed issue #38336: `DateTimeSensor()` does not work with `datetime`s rendered via `render_template_as_native_obj=True`
URL: https://github.com/apache/airflow/issues/38336
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] `DateTimeSensor()` does not work with `datetime`s rendered via `render_template_as_native_obj=True` [airflow]
Posted by "nailo2c (via GitHub)" <gi...@apache.org>.
nailo2c commented on issue #38336:
URL: https://github.com/apache/airflow/issues/38336#issuecomment-2888776376
I'd like to take this one on.
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [I] `DateTimeSensor()` does not work with `datetime`s rendered via `render_template_as_native_obj=True` [airflow]
Posted by "pierregillet (via GitHub)" <gi...@apache.org>.
pierregillet commented on issue #38336:
URL: https://github.com/apache/airflow/issues/38336#issuecomment-2222505814
I encountered the same error, exactly the same use case (wait some time after `data_interval_end` before continuing).
Thanks for the temporary fix!
--
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: commits-unsubscribe@airflow.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org