ephraimbuddy commented on code in PR #32177:
URL: https://github.com/apache/airflow/pull/32177#discussion_r1250441632
##########
airflow/utils/db.py:
##########
@@ -1143,7 +1144,7 @@ def check_run_id_null(session: Session) -> Iterable[str]:
dagrun_table.c.run_id.is_(None),
dagrun_table.c.execution_date.is_(None),
)
- invalid_dagrun_count =
session.query(func.count(dagrun_table.c.id)).filter(invalid_dagrun_filter).scalar()
+ invalid_dagrun_count =
session.scalar(select(func.count(dagrun_table.c.id)).filter(invalid_dagrun_filter))
Review Comment:
```suggestion
invalid_dagrun_count =
session.scalar(select(func.count(dagrun_table.c.id)).where(invalid_dagrun_filter))
```
I think `filter` is removed in 2.0, also, it feels much better when you read
the query with `where`
##########
airflow/www/views.py:
##########
@@ -933,10 +938,13 @@ def _iter_parsed_moved_data_table_names():
permissions.RESOURCE_ADMIN_MENU,
) in user_permissions and conf.getboolean("webserver",
"warn_deployment_exposure"):
robots_file_access_count = (
- session.query(Log)
- .filter(Log.event == "robots")
- .filter(Log.dttm > (utcnow() - datetime.timedelta(days=7)))
- .count()
+ select(Log)
+ .where(Log.event == "robots")
+ .where(Log.dttm > (utcnow() - datetime.timedelta(days=7)))
+ # .count()
Review Comment:
```suggestion
```
##########
airflow/utils/db.py:
##########
@@ -1331,9 +1333,9 @@ def _move_duplicate_data_to_new_table(
"""
bind = session.get_bind()
dialect_name = bind.dialect.name
+
query = (
- session.query(source_table)
- .with_entities(*[getattr(source_table.c, x.name).label(str(x.name))
for x in source_table.columns])
+ session.select(*[getattr(source_table.c, x.name).label(str(x.name))
for x in source_table.columns])
Review Comment:
There's no `session.select`. This will fail
##########
airflow/www/views.py:
##########
@@ -4721,7 +4734,9 @@ def action_mulduplicate(self, connections, session:
Session = NEW_SESSION):
potential_connection_ids = [f"{base_conn_id}_copy{i}" for i in
range(1, 11)]
- query =
session.query(Connection.conn_id).filter(Connection.conn_id.in_(potential_connection_ids))
+ query = session.execute(
Review Comment:
We can use scalars here then in line 4741 do:
```python
found_conn_id_set = {conn_id for conn_id in query}
```
That's, remove the comma
--
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]