Skip to content

Best Practice for using variable in timetable seems obsolete #61497

Closed

Description

@darkag

What do you see as an issue?

hello, it seems that the example provided in this page https://airflow.apache.org/docs/apache-airflow/stable/best-practices.html#timetables
is not valid anymore, not only it doesn't works but it also seems to crash dag processor

Image

Solving the problem

If this example is not valid it should be removed (and maybe dag processor should not crash and provide import issue on UI)

Anything else

No response

Are you willing to submit PR?

  • Yes I am willing to submit a PR!

Code of Conduct

Activity

  1. added
    kind:bug
    needs-triage
    on Feb 5, 2026
  2. jroachgolf84 commented on Feb 5, 2026

    @jroachgolf84
    Collaborator

    @darkag - can you share a snip of the code that you're authoring that's causing this exception?

  3. darkag commented on Feb 5, 2026

    @darkag
    ContributorAuthor

    sure, here is the timetable code

    # plugins/special_days_timetable.py
    from datetime import timedelta
    from airflow.sdk import Variable
    import pendulum
    from airflow.plugins_manager import AirflowPlugin
    from airflow.timetables.base import Timetable, DagRunInfo, DataInterval, TimeRestriction
    from pendulum import DateTime
    from typing import Optional
    
    class SpecialDaysTimetable(Timetable):
    
        def __init__(self, tz: str = "Europe/Paris"):
            self._tz = pendulum.timezone(tz)
            self.is_special_date = Variable.get("is_special", "False") == "True"
    
        @property
        def summary(self) -> str:
            return f"Special date"
    
        # --- Timetable API ---
        def infer_manual_data_interval(self, run_after: DateTime) -> DataInterval:
            # intervalle de 30 minutes se terminant à run_after
            start = run_after.in_timezone(self._tz) - timedelta(minutes=30)
            return DataInterval(start=start, end=run_after.in_timezone(self._tz))
    
        def next_dagrun_info(
            self,
            *,
            last_automated_data_interval: Optional[DataInterval],
            restriction: TimeRestriction,
        ) -> Optional[DagRunInfo]:
            return None        
    
    
    class SpecialDaysTimetablePlugin(AirflowPlugin):
        name = "special_days_timetable_plugin"
        timetables = [SpecialDaysTimetable]

    and the dag using it

    import pendulum
    from datetime import timedelta, datetime
    from airflow.decorators import dag,task
    from special_days_timetable import SpecialDaysTimetable
    
    local_tz = pendulum.timezone("Europe/Paris")
    
    default_args = {
        'owner': 'cineentrees',
        'depends_on_past': False,
        'email_on_failure': True,
        'email_on_retry': False,
        'retries': 0,
        'retry_delay': timedelta(minutes=1),
    }
    
    @dag(
        dag_id="test_of_special_days",
        default_args=default_args,
        schedule=SpecialDaysTimetable(),
        start_date=datetime(2023,1,1, 4, tzinfo=local_tz),
        max_active_runs=1,
        catchup=False,
        dagrun_timeout=timedelta(minutes=10),
    )
    def run_dag():
    
        @task()
        def first_task():
            pass
        
        first_task()
    
    run_dag()

    everything is ok if I replace self.is_special_date = Variable.get("is_special", "False") == "True" by self.is_special_date = False

  4. removed
    needs-triage
    on Feb 12, 2026
  5. changed the title [-]Best Practice for using variable in timetable seems obsolet[/-] [+]Best Practice for using variable in timetable seems obsolete[/+] on Feb 12, 2026
  6. shashbha14 commented on Feb 16, 2026

    @shashbha14
    Contributor

    I would like to work on this issue. Please assign me.

  7. jroachgolf84 commented on Feb 16, 2026

    @jroachgolf84
    Collaborator

    @shashbha14, looks like a PR has already been created for this issue. Feel free to find another issue to contribute to!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions