henry3260 commented on code in PR #58852:
URL: https://github.com/apache/airflow/pull/58852#discussion_r2620290777
##########
airflow-core/src/airflow/timetables/base.py:
##########
@@ -206,6 +206,34 @@ def summary(self) -> str:
"""
return type(self).__name__
+ @property
+ def type_name(self) -> str:
+ """
+ This is primarily intended for filtering dags based on timetable type.
+
+ For built-in timetables (defined in airflow.timetables or
+ airflow.sdk.definitions.timetables), this returns the class name only.
+ For custom timetables (user-defined via plugins), this returns the full
+ import path to avoid confusion between multiple implementations with
the
+ same class name.
+
+ For example, built-in timetables return:
+ ``"NullTimetable"`` or ``"CronDataIntervalTimetable"``
+ while custom timetables return the full path:
+ ``"my_company.timetables.CustomTimetable"``
+ """
+ module = self.__class__.__module__
+ class_name = self.__class__.__name__
+
+ # Built-in timetables from Core or SDK use class name only
+ if module.startswith("airflow.timetables.") or module.startswith(
+ "airflow.sdk.definitions.timetables."
+ ):
+ return class_name
Review Comment:
> This would not work for types in `airflow.sdk.definitions.timetables`
since they don’t inherit from this class. I also feel there’s probably a better
way to do this than string manipulation (which can break too easily if we move
the classes around).
I agree. Relying on raw strings is fragile.
Thanks for the catch regarding the SDK inheritance and the fragility of
string parsing.
I propose moving this logic to a standalone utility function to handle both
Core and SDK objects. Regarding the string manipulation, would checking if the
class module is within the airflow package be acceptable, or should we maintain
a set of allowed built-in modules/classes to be explicit?
--
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]