Lee-W commented on code in PR #63185:
URL: https://github.com/apache/airflow/pull/63185#discussion_r3541216133
##########
airflow-core/src/airflow/dag_processing/bundles/manager.py:
##########
@@ -34,17 +36,48 @@
from airflow.models.team import Team
from airflow.providers_manager import ProvidersManager
from airflow.utils.log.logging_mixin import LoggingMixin
-from airflow.utils.session import NEW_SESSION, provide_session
+from airflow.utils.session import NEW_SESSION, create_session, provide_session
if TYPE_CHECKING:
from collections.abc import Iterable
+ from sqlalchemy.engine import CursorResult
from sqlalchemy.orm import Session
log = logging.getLogger(__name__)
_example_dag_bundle_name = "example_dags"
+# Chunk size for the one-time startup repair of unconfigured bundles.
+_REASSIGN_BATCH_SIZE = 1000
+
+
+def _best_bundle_for_fileloc(
+ fileloc: str, descending_bundle_paths: dict[str, Path]
+) -> tuple[str, str] | None:
+ """
+ Return ``(bundle_name, relative_fileloc)`` for the first bundle whose path
contains ``fileloc``.
+
+ ``descending_bundle_paths`` must be sorted by path length descending so
+ the deepest bundle wins when paths overlap.
+
+ Returns ``None`` when ``fileloc`` is not under any bundle's path.
+
+ Uses the same plain ``Path.relative_to`` check as
+ ``BaseDagImporter.get_relative_path``, so the ``relative_fileloc`` written
+ here matches what the next parse computes for the same file. Filelocs are
+ produced by the Dag processor parsing admin-controlled bundle files, so
they
+ are trusted and need no path-traversal normalization.
+ """
+ file_path = Path(fileloc)
+ for name, path in descending_bundle_paths.items():
+ try:
+ relative = file_path.relative_to(path)
+ except ValueError:
+ continue
Review Comment:
oh, got your point
--
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]