Nataneljpwd commented on code in PR #55253:
URL: https://github.com/apache/airflow/pull/55253#discussion_r2322259997
##########
airflow-core/src/airflow/api_fastapi/app.py:
##########
@@ -200,5 +200,17 @@ def init_plugins(app: FastAPI) -> None:
log.error("'middleware' key is missing for the fastapi middleware:
%s", name)
continue
+ # Resolve middleware string to class if needed
+ if isinstance(middleware, str):
+ try:
+ from airflow.utils.module_loading import import_string
+ middleware = import_string(middleware)
Review Comment:
Is this to import the middleware string as Python code?
Just a question as I haven't worked on this part of airflow yet
##########
airflow-core/src/airflow/plugins_manager.py:
##########
@@ -700,3 +700,36 @@ def initialize_priority_weight_strategy_plugins():
**airflow_priority_weight_strategies,
**plugins_priority_weight_strategy_classes,
}
+
+
+def import_from_plugins(class_name: str):
+ """
+ Search for a class in all loaded plugin modules.
+
+ Args:
+ class_name: Simple class name (e.g., "AddHeaderMiddleware")
+
+ Returns:
+ The class object if found
+
+ Raises:
+ ImportError: If class not found in any plugin module
+ """
+ # Check if plugins are loaded
+ if plugins is None:
+ raise ImportError(f'Class "{class_name}" not found - no plugins
loaded')
+
+ # Search in all loaded plugin modules
+ for plugin_instance in plugins:
+ plugin_module_name = plugin_instance.__class__.__module__
+
+ # Get the plugin module from sys.modules
+ if plugin_module_name in sys.modules:
Review Comment:
I think it would be better if you inverse the if and add the second
condition with with an or statement, and you could also use the := operator to
make it shorter and less nested.
##########
airflow-core/src/airflow/api_fastapi/app.py:
##########
@@ -200,5 +200,17 @@ def init_plugins(app: FastAPI) -> None:
log.error("'middleware' key is missing for the fastapi middleware:
%s", name)
continue
+ # Resolve middleware string to class if needed
+ if isinstance(middleware, str):
+ try:
+ from airflow.utils.module_loading import import_string
+ middleware = import_string(middleware)
Review Comment:
Is this to import the middleware string as Python code?
Just a question as I haven't worked on this part of airflow yet
If so, is it desired?
--
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]