Skip to content

Conversation

@jscheffl
Copy link
Contributor

@jscheffl jscheffl commented Jun 1, 2024

I noticed that we have some example plugins we ship in our source code, but so far we are limited not being able to "eat our own dog-food" with the example DAGs. Plugins so far needed to be deployed by deployment manager.

This PR improves the plugin manager slightly in the way that plugins contained in example DAGs folder in source are loaded as well when example DAGs are loaded.

This enables us(in separate PRs in future... soon?) to really use timetables in the example DAGs and not only have code examples linked in documentation.

FYI @hussein-awala I remember you also had a hard time making an example working in our PR #36029

@jscheffl jscheffl added area:plugins type:improvement Changelog: Improvements labels Jun 1, 2024
@potiuk
Copy link
Member

potiuk commented Jun 2, 2024

Some serialization tests are failing but I like it :)

@jscheffl jscheffl requested review from hussein-awala and potiuk June 2, 2024 20:50
@jscheffl jscheffl force-pushed the feature/load-example-plugins-with-example-dags branch from 899fe3e to c09b8d5 Compare June 5, 2024 22:04
@jscheffl jscheffl requested a review from uranusjr June 5, 2024 22:06
@jscheffl jscheffl force-pushed the feature/load-example-plugins-with-example-dags branch from e10c88d to 3fda785 Compare July 7, 2024 08:24
Copy link
Member

@potiuk potiuk left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. @uranusjr ?

Copy link
Member

@uranusjr uranusjr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me, one minor thought.

@jscheffl jscheffl merged commit 0bd1dfa into apache:main Jul 12, 2024
@ephraimbuddy ephraimbuddy added this to the Airflow 2.10.0 milestone Jul 23, 2024
romsharon98 pushed a commit to romsharon98/airflow that referenced this pull request Jul 26, 2024
* Load Example Plugins with Example DAGs

* Make testing timetables with unique name to fix serialization

* Fix loading, move example timetable and fix pytests

* Fix pytests with custom timetables

* Fix pytests with custom timetables, mock loading issues in python 3.8

* Fix pytests with custom timetables, mock loading issues in python 3.8
@zachliu
Copy link
Contributor

zachliu commented Sep 9, 2024

Sorry for commenting on a merged PR. Just wanna make sure this is a real issue before i create an issue 😅

I'm on Airflow 2.10.1.

The PR does make sure the plugin is loaded when load_examples = True. And the DAG itself runs ok. No "Broken Dag" import errors or anything. The UI -> Admin -> Plugins shows the 3 plugins from the example_dags/plugins

However, both the sync-perm cli and the plugins cli don't agree with it. When executing airflow sync-perm --include-dags -v, it always errors out on this example dag:

{serialized_dag.py:200} DEBUG - Deserializing DAG: example_workday_timetable
{plugins_manager.py:351} DEBUG - Plugins are already loaded. Skipping.
{plugins_manager.py:484} DEBUG - Initialize extra timetables plugins
{cli_action_loggers.py:98} DEBUG - Calling callbacks: []
Traceback (most recent call last):
  File "/usr/local/airflow/.local/bin/airflow", line 8, in <module>
    sys.exit(main())
             ^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/__main__.py", line 62, in main
    args.func(args)
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/cli/cli_config.py", line 49, in command
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/utils/cli.py", line 115, in wrapper
    return f(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/utils/providers_configuration_loader.py", line 55, in wrapped_function
    return func(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/providers/fab/auth_manager/cli_commands/sync_perm_command.py", line 39, in sync_perm
    appbuilder.sm.create_dag_specific_permissions()
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/providers/fab/auth_manager/security_manager/override.py", line 1072, in create_dag_specific_permissions
    dagbag.collect_dags_from_db()
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/models/dagbag.py", line 628, in collect_dags_from_db
    self.dags = SerializedDagModel.read_all_dags()
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/utils/session.py", line 97, in wrapper
    return func(*args, session=session, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/models/serialized_dag.py", line 201, in read_all_dags
    dag = row.dag
          ^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/models/serialized_dag.py", line 235, in dag
    return SerializedDAG.from_dict(data)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/serialization/serialized_objects.py", line 1776, in from_dict
    return cls.deserialize_dag(serialized_obj["dag"])
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/serialization/serialized_objects.py", line 1704, in deserialize_dag
    v = decode_timetable(v)
        ^^^^^^^^^^^^^^^^^^^
  File "/usr/local/airflow/.local/lib/python3.11/site-packages/airflow/serialization/serialized_objects.py", line 329, in decode_timetable
    raise _TimetableNotRegistered(importable_string)
airflow.serialization.serialized_objects._TimetableNotRegistered: Timetable class 'airflow.example_dags.plugins.workday.AfterWorkdayTimetable' is not registered or you have a top level database access that disrupted the session. Please check the airflow best practices documentation.

and when executing airflow plugins -o table -v, the 3 plugins from example_dags/plugins are not in the output table.

of course if I set load_examples = False, the sync-perm and plugin work fine without any errors

the only way that I can run both this example and the cli commands is:

  1. copy the source code airflow/example_dags/plugins/workday.py to my own airflow/plugins (in my airflow.cfg, i have plugins_folder = /usr/local/airflow/plugins)
  2. re-create the example as one of my own dags but import from my own plugins: from workday import AfterWorkdayTimetable

@jscheffl
Copy link
Contributor Author

Sorry for commenting on a merged PR. Just wanna make sure this is a real issue before i create an issue 😅

That is okay. And I assume we have not tried the CLI after the change applied with example DAGs being loaded. Can you raise a new bug for this? (related to this PR?)

Did you set "load examples=True" in your config or did you see this error after running with examples loaded once? Because if the CLI runs w/o examples explicitly turned-on but DAGs have been parsed to DB with examples, this might be a config mis-match.

@zachliu
Copy link
Contributor

zachliu commented Sep 10, 2024

Sorry for commenting on a merged PR. Just wanna make sure this is a real issue before i create an issue 😅

That is okay. And I assume we have not tried the CLI after the change applied with example DAGs being loaded. Can you raise a new bug for this? (related to this PR?)

Did you set "load examples=True" in your config or did you see this error after running with examples loaded once? Because if the CLI runs w/o examples explicitly turned-on but DAGs have been parsed to DB with examples, this might be a config mis-match.

Yes, I've been setting load_examples=True. I'll create a new issue today.

@jscheffl jscheffl deleted the feature/load-example-plugins-with-example-dags branch October 5, 2025 07:39
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area:plugins type:improvement Changelog: Improvements

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants