hussein-awala commented on code in PR #33403:
URL: https://github.com/apache/airflow/pull/33403#discussion_r1295665756
##########
airflow/triggers/temporal.py:
##########
@@ -34,18 +35,30 @@ class DateTimeTrigger(BaseTrigger):
The provided datetime MUST be in UTC.
"""
- def __init__(self, moment: datetime.datetime):
+ def __init__(self, moment: datetime.datetime, *, soft_fail: bool = False)
-> None:
super().__init__()
+ skipping_message_postfix = "Skipping due to soft_fail is set to True."
if not isinstance(moment, datetime.datetime):
- raise TypeError(f"Expected datetime.datetime type for moment. Got
{type(moment)}")
+ message = f"Expected datetime.datetime type for moment. Got
{type(moment)}"
+ if soft_fail:
+ raise AirflowSkipException(f"{message}.
{skipping_message_postfix}")
+ raise TypeError(message)
# Make sure it's in UTC
elif moment.tzinfo is None:
- raise ValueError("You cannot pass naive datetimes")
+ message = "You cannot pass naive datetimes"
+ if soft_fail:
+ raise AirflowSkipException(f"{message}.
{skipping_message_postfix}")
Review Comment:
What about:
```python
try:
self.defer(
trigger=DateTimeTrigger(moment=target_dttm,
soft_fail=self.soft_fail),
method_name="execute_complete",
)
except Exception as e:
raise AirflowException(str(e))
```
or just changing `raise TypeError(message)` and `raise ValueError` to
`AirflowException`.
In both cases the exception will be cached by BaseSensor, and a
`AirflowSkipException` will be raised when soft_fail is True. I'm trying to
avoid complicating the trigger code, and duplicating the soft fail logic.
cc: @uranusjr @potiuk WDYT?
--
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]