SamWheating commented on a change in pull request #18924:
URL: https://github.com/apache/airflow/pull/18924#discussion_r732291747
##########
File path: airflow/api_connexion/endpoints/dag_endpoint.py
##########
@@ -60,13 +60,16 @@ def get_dag_details(dag_id):
@security.requires_access([(permissions.ACTION_CAN_READ,
permissions.RESOURCE_DAG)])
@format_parameters({'limit': check_limit})
@provide_session
-def get_dags(limit, session, offset=0, only_active=True, tags=None):
+def get_dags(limit, session, offset=0, only_active=True, tags=None,
search=None):
"""Get all DAGs."""
if only_active:
dags_query = session.query(DagModel).filter(~DagModel.is_subdag,
DagModel.is_active)
else:
dags_query = session.query(DagModel).filter(~DagModel.is_subdag)
+ if search:
+ dags_query = dags_query.filter(DagModel.dag_id.ilike(f'%{search}%'))
Review comment:
Interesting - which part would you extract out? If we're just extracting
the ilike argument generation then I guess it would look something like this:
```python
def get_formatted_search(search_term):
return f"%{search_term}%"
# in another file:
@security.requires_access([(permissions.ACTION_CAN_READ,
permissions.RESOURCE_DAG)])
@format_parameters({'limit': check_limit})
@provide_session
def get_dags(limit, session, offset=0, only_active=True, tags=None,
dag_id_pattern=None):
"""Get all DAGs."""
if only_active:
dags_query = session.query(DagModel).filter(~DagModel.is_subdag,
DagModel.is_active)
else:
dags_query = session.query(DagModel).filter(~DagModel.is_subdag)
if dag_id_pattern:
dags_query =
dags_query.filter(DagModel.dag_id.ilike(get_formatted_search(dag_id_pattern)))
```
Which is a bit of an unnecessary optimization in my opinion.
Unless you were thinking about a function which actually returns a modified
`session.query()` object?
--
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]