uranusjr commented on a change in pull request #21264:
URL: https://github.com/apache/airflow/pull/21264#discussion_r798239432
##########
File path: airflow/utils/trigger_rule.py
##########
@@ -34,20 +36,16 @@ class TriggerRule:
ALWAYS = 'always'
NONE_FAILED_MIN_ONE_SUCCESS = "none_failed_min_one_success"
- _ALL_TRIGGER_RULES: Set[str] = set()
-
@classmethod
- def is_valid(cls, trigger_rule):
+ def is_valid(cls, trigger_rule: str) -> bool:
"""Validates a trigger rule."""
return trigger_rule in cls.all_triggers()
@classmethod
- def all_triggers(cls):
+ @cache
+ def all_triggers(cls) -> Set[str]:
"""Returns all trigger rules."""
- if not cls._ALL_TRIGGER_RULES:
- cls._ALL_TRIGGER_RULES = {
- getattr(cls, attr)
- for attr in dir(cls)
- if not attr.startswith("_") and not callable(getattr(cls,
attr))
- }
- return cls._ALL_TRIGGER_RULES
+ return {getattr(cls, attr) for attr in dir(cls) if not
attr.startswith("_")}
Review comment:
```suggestion
return set(cls.__members__.values())
```
The caching seems excessive and unnecessary though, this function is only
called when a DAG is being initiated. I would remove `all_triggers` entirely
and just rely on `__members__`.
--
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]