pierrejeambrun commented on code in PR #69270:
URL: https://github.com/apache/airflow/pull/69270#discussion_r3822038813
##########
shared/observability/src/airflow_shared/observability/metrics/stats.py:
##########
@@ -105,6 +106,37 @@ def initialize(
_factory = factory
_backend = None
_export_legacy_names = export_legacy_names
+ _propagate_to_sibling_modules(factory=factory,
export_legacy_names=export_legacy_names)
+
+
+def _propagate_to_sibling_modules(
+ *,
+ factory: Callable[[], StatsLogger | NoStatsLogger],
+ export_legacy_names: bool,
+) -> None:
+ """
+ Apply the same configuration to other loaded copies of this module.
+
+ This source file is symlinked into multiple distributions (e.g.
``airflow-core`` and
+ ``task-sdk``), each importing it under a different module name
(``airflow._shared...`` vs
+ ``airflow.sdk._shared...``). Python treats each as a distinct module
object with its own
+ module-level globals, so a process that has both loaded (e.g. the
scheduler, which also runs
Review Comment:
I think this can still be a problem if there is a local import, or somehow
the plugin Stat is imported after core is initialized.
##########
shared/observability/src/airflow_shared/observability/metrics/stats.py:
##########
@@ -105,6 +106,37 @@ def initialize(
_factory = factory
_backend = None
_export_legacy_names = export_legacy_names
+ _propagate_to_sibling_modules(factory=factory,
export_legacy_names=export_legacy_names)
+
+
+def _propagate_to_sibling_modules(
+ *,
+ factory: Callable[[], StatsLogger | NoStatsLogger],
+ export_legacy_names: bool,
+) -> None:
+ """
+ Apply the same configuration to other loaded copies of this module.
+
+ This source file is symlinked into multiple distributions (e.g.
``airflow-core`` and
+ ``task-sdk``), each importing it under a different module name
(``airflow._shared...`` vs
+ ``airflow.sdk._shared...``). Python treats each as a distinct module
object with its own
+ module-level globals, so a process that has both loaded (e.g. the
scheduler, which also runs
Review Comment:
And to be honest this piece of code seems quite hacky.
--
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]