[ https://issues.apache.org/jira/browse/AIRFLOW-6586?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17100096#comment-17100096 ]
ASF GitHub Bot commented on AIRFLOW-6586: ----------------------------------------- mik-laj commented on a change in pull request #7197: URL: https://github.com/apache/airflow/pull/7197#discussion_r420274026 ########## File path: airflow/sensors/base_sensor_operator.py ########## @@ -176,3 +179,60 @@ def deps(self): if self.reschedule: return BaseOperator.deps.fget(self) | {ReadyToRescheduleDep()} return BaseOperator.deps.fget(self) + + +def poke_mode_only(cls): + """ + Class Decorator for child classes of BaseSensorOperator to indicate + that instances of this class are only safe to use poke mode. + + Will decorate all methods in the class to assert they did not change + the mode from 'poke'. + + :param cls: BaseSensor class to enforce methods only use 'poke' mode. + :type cls: type + """ + def decorate(cls): + if not issubclass(cls, BaseSensorOperator): + raise ValueError("poke_mode_only decorator should only be " + + "applied to subclasses of BaseSensorOperator," + + f" got:{cls}.") + for method in inspect.getmembers(cls, inspect.isfunction): + setattr(cls, method[0], _poke_mode_only_func_decorator(method)) + return cls + + return decorate(cls) + + +def _poke_mode_only_func_decorator(method): + """ + Decorator that raises an error if method changed mode to anything but + 'poke'.function + :param method: BaseSensor class to enforce methods only use 'poke' mode. Review comment: ```suggestion :param method: BaseSensor class to enforce methods only use 'poke' mode. ``` ---------------------------------------------------------------- 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. For queries about this service, please contact Infrastructure at: us...@infra.apache.org > GCSUploadSessionCompleteSensor breaks in reschedule mode. > --------------------------------------------------------- > > Key: AIRFLOW-6586 > URL: https://issues.apache.org/jira/browse/AIRFLOW-6586 > Project: Apache Airflow > Issue Type: Bug > Components: operators > Affects Versions: 1.10.3 > Reporter: Jacob Ferriero > Priority: Minor > > This sensor is stateful and loses state between reschedules. > We should: > # Warn about this in docstring > # Add a `poke_mode_only` class decorator for sensors that aren't safe in > reschedule mode. -- This message was sent by Atlassian Jira (v8.3.4#803005)