RabahAmrouche05 commented on code in PR #68544:
URL: https://github.com/apache/airflow/pull/68544#discussion_r3553923036


##########
airflow-core/src/airflow/api_fastapi/common/parameters.py:
##########
@@ -894,6 +894,43 @@ def depends(cls, owners: list[str] = 
Query(default_factory=list)) -> _OwnersFilt
         return cls().set_value(owners)
 
 
+class _RelativeFilelocPrefixFilter(BaseParam[str | None]):
+    """
+    Filter Dags by the folder they live in, derived from ``relative_fileloc``.
+
+    The value is treated as a directory path relative to the bundle root (e.g.
+    ``team_a/etl``). It matches every Dag whose file lives directly in that 
folder
+    or in any of its subfolders, using an escaped ``LIKE 'team_a/etl/%'`` so a
+    folder name is never a substring/prefix of another (``team_a`` won't match
+    ``team_alpha``). Dags at the bundle root (no ``/`` in ``relative_fileloc``)
+    are not matched by any folder value and appear only when no folder is 
selected.
+    """
+
+    def to_orm(self, select: Select) -> Select:
+        if self.value is None and self.skip_none:
+            return select
+
+        if not self.value:
+            return select
+
+        directory = self.value.rstrip("/")

Review Comment:
   That's a good question. `relative_fileloc` comes from 
`str(Path(file_path).relative_to(bundle_path))` in the dag processor 
(importers/base.py), so on the platforms Airflow runs its components on (posix) 
the separator is always `/`. And on posix `/` can't appear inside a file or 
folder name, so splitting on it isn't ambiguous. I'm also using 
`PurePosixPath(...).parent` to derive the folder, not a raw split.
   
   The only case where this wouldn't hold is a Windows-style `\` path, which 
isn't a supported setup for the scheduler/dag processor afaik.
   
   If we want to be extra safe we could normalize `relative_fileloc` to posix 
at the source (`.as_posix()`), but that touches every consumer of the field, so 
it feels like a separate change rather than something for this PR. Happy to 
follow whatever you and @jedcunningham think is best here.
   



-- 
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]

Reply via email to