You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@airflow.apache.org by GitBox <gi...@apache.org> on 2022/08/08 09:08:48 UTC
[GitHub] [airflow] ephraimbuddy opened a new pull request, #25594: Fix mapped sensor with reschedule mode
ephraimbuddy opened a new pull request, #25594:
URL: https://github.com/apache/airflow/pull/25594
There are two issues with mapped sensor with `reschedule` mode. First, the reschedule table is being populated with a default map_index of -1 even when the map_index is not -1. Secondly, MappedOperator does not have the `ReadyToReschedule` dependency.
This PR is an attempt to fix this
closes: https://github.com/apache/airflow/issues/25095
--
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
[GitHub] [airflow] uranusjr commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r941275099
##########
airflow/ti_deps/deps/ready_to_reschedule.py:
##########
@@ -40,7 +40,8 @@ def _get_dep_statuses(self, ti, session, dep_context):
considered as passed. This dependency fails if the latest reschedule
request's reschedule date is still in future.
"""
- if not getattr(ti.task, "reschedule", False):
+ is_mapped = ti.task.is_mapped
+ if not is_mapped and not getattr(ti.task, "reschedule", False):
Review Comment:
Worth a comment here (and below) to note why we explicitly exclude mapped operators this this function.
--
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
[GitHub] [airflow] ephraimbuddy commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r940627184
##########
airflow/ti_deps/deps/ready_to_reschedule.py:
##########
@@ -62,6 +63,9 @@ def _get_dep_statuses(self, ti, session, dep_context):
.first()
)
if not task_reschedule:
+ if is_mapped:
+ yield self._passing_status(reason="The task is mapped and not in reschedule mode")
+ return
Review Comment:
Handling the logic here is the simplest solution among many others I considered.
`MappedOperator` doesn't serialize sensor attributes.
--
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
[GitHub] [airflow] ephraimbuddy commented on pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on PR #25594:
URL: https://github.com/apache/airflow/pull/25594#issuecomment-1209255782
> > MappedOperator does not have the `ReadyToReschedule` dependency.
>
> Hmm, I am not sure putting ReadyToReschedule in BaseOperator is a good idea. Why is this needed though? MappedOperator reads `deps` when the wrapped class calls `expand`, so when you do `Sensor.expand()`, the resulting MappedOperator should automatically contain ReadyToReschedule. Is this dep lost somewhere in the scheduler?
Figured and fixed the `deps` part and added a test for the reserialization. There seems to be a problem in mapped op serialization which I think will affect other custom operators that added extra serializable fields. Once it's fixed for the sensor, it'll be fixed for all. For now, the logic is still in reschedule dep check for the reschedule attribute
--
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
[GitHub] [airflow] uranusjr commented on pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
uranusjr commented on PR #25594:
URL: https://github.com/apache/airflow/pull/25594#issuecomment-1210345514
We need some more tests on
1. A mapped sensor with another mode (not `reschedule`) and ensure it also works correctly
2. A sensor mapped against different modes (`PythonSensor.expand(mode=["reschedule", "poke"]`, for example). Does this make sense? If it does, we need to ensure it behaves as expected.
--
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
[GitHub] [airflow] ephraimbuddy commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r940008337
##########
airflow/models/mappedoperator.py:
##########
@@ -383,6 +386,13 @@ def inherits_from_empty_operator(self) -> bool:
"""Implementing Operator."""
return self._is_empty
+ @property
+ def reschedule(self) -> bool:
+ """Check if the operator is a sensor and has mode reschedule"""
+ if self._is_sensor:
+ return self.partial_kwargs['mode'] == 'reschedule'
+ raise AttributeError("reschedule is not defined for MappedOperator")
+
Review Comment:
@uranusjr What's your thought about this approach?
--
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
[GitHub] [airflow] ephraimbuddy merged pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
ephraimbuddy merged PR #25594:
URL: https://github.com/apache/airflow/pull/25594
--
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
[GitHub] [airflow] uranusjr commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r941275666
##########
tests/ti_deps/deps/test_ready_to_reschedule_dep.py:
##########
@@ -32,11 +32,13 @@ class TestNotInReschedulePeriodDep(unittest.TestCase):
def _get_task_instance(self, state):
dag = DAG('test_dag')
task = Mock(dag=dag, reschedule=True)
+ task.is_mapped = False
Review Comment:
```suggestion
task = Mock(dag=dag, reschedule=True, is_mapped=False)
```
##########
tests/ti_deps/deps/test_ready_to_reschedule_dep.py:
##########
@@ -32,11 +32,13 @@ class TestNotInReschedulePeriodDep(unittest.TestCase):
def _get_task_instance(self, state):
dag = DAG('test_dag')
task = Mock(dag=dag, reschedule=True)
+ task.is_mapped = False
ti = TaskInstance(task=task, state=state, run_id=None)
return ti
def _get_task_reschedule(self, reschedule_date):
task = Mock(dag_id='test_dag', task_id='test_task')
+ task.is_mapped = False
Review Comment:
```suggestion
task = Mock(dag_id='test_dag', task_id='test_task', is_mapped=False)
```
--
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
[GitHub] [airflow] ephraimbuddy commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r940031882
##########
airflow/models/mappedoperator.py:
##########
@@ -383,6 +386,13 @@ def inherits_from_empty_operator(self) -> bool:
"""Implementing Operator."""
return self._is_empty
+ @property
+ def reschedule(self) -> bool:
+ """Check if the operator is a sensor and has mode reschedule"""
+ if self._is_sensor:
+ return self.partial_kwargs['mode'] == 'reschedule'
+ raise AttributeError("reschedule is not defined for MappedOperator")
+
Review Comment:
Another option I'm exploring is changing the way the readytoreschedule dep is checked
--
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
[GitHub] [airflow] uranusjr commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r940113016
##########
airflow/models/mappedoperator.py:
##########
@@ -383,6 +386,13 @@ def inherits_from_empty_operator(self) -> bool:
"""Implementing Operator."""
return self._is_empty
+ @property
+ def reschedule(self) -> bool:
+ """Check if the operator is a sensor and has mode reschedule"""
+ if self._is_sensor:
+ return self.partial_kwargs['mode'] == 'reschedule'
+ raise AttributeError("reschedule is not defined for MappedOperator")
+
Review Comment:
Would it be easier if we just make `reschedule` a separate attribute, and calculate that when a MappedOperator is created? This seem easier than adding a new `_is_sensor` that does not exist on BaseOperator.
--
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
[GitHub] [airflow] ephraimbuddy commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r940628841
##########
airflow/ti_deps/deps/ready_to_reschedule.py:
##########
@@ -62,6 +63,9 @@ def _get_dep_statuses(self, ti, session, dep_context):
.first()
)
if not task_reschedule:
+ if is_mapped:
+ yield self._passing_status(reason="The task is mapped and not in reschedule mode")
+ return
Review Comment:
Having `MappedSensor` seems like a better solution.
--
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
[GitHub] [airflow] uranusjr commented on pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
uranusjr commented on PR #25594:
URL: https://github.com/apache/airflow/pull/25594#issuecomment-1208997462
> MappedOperator does not have the `ReadyToReschedule` dependency.
Hmm, I am not sure putting ReadyToReschedule in BaseOperator is a good idea. Why is this needed though? MappedOperator reads `deps` when the wrapped class calls `expand`, so when you do `Sensor.expand()`, the resulting MappedOperator should automatically contain ReadyToReschedule. Is this dep lost somewhere in the scheduler?
--
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
[GitHub] [airflow] ephraimbuddy commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
ephraimbuddy commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r940031882
##########
airflow/models/mappedoperator.py:
##########
@@ -383,6 +386,13 @@ def inherits_from_empty_operator(self) -> bool:
"""Implementing Operator."""
return self._is_empty
+ @property
+ def reschedule(self) -> bool:
+ """Check if the operator is a sensor and has mode reschedule"""
+ if self._is_sensor:
+ return self.partial_kwargs['mode'] == 'reschedule'
+ raise AttributeError("reschedule is not defined for MappedOperator")
+
Review Comment:
Another option I'm exploring is changing the way the readytoreschedule dep is checked
--
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
[GitHub] [airflow] uranusjr commented on a diff in pull request #25594: Fix mapped sensor with reschedule mode
Posted by GitBox <gi...@apache.org>.
uranusjr commented on code in PR #25594:
URL: https://github.com/apache/airflow/pull/25594#discussion_r942175585
##########
airflow/ti_deps/deps/ready_to_reschedule.py:
##########
@@ -40,7 +40,9 @@ def _get_dep_statuses(self, ti, session, dep_context):
considered as passed. This dependency fails if the latest reschedule
request's reschedule date is still in future.
"""
- if not getattr(ti.task, "reschedule", False):
+ is_mapped = ti.task.is_mapped
+ if not is_mapped and not getattr(ti.task, "reschedule", False):
+ # Mapped sensors don't currently have the reschedule property,
Review Comment:
```suggestion
# Mapped sensors don't have the reschedule property (it can only
# be calculated after unmapping), so we don't check them here.
# They are handled below by checking TaskReschedule instead.
```
--
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