jason810496 commented on code in PR #76515:
URL: https://github.com/apache/airflow/pull/76515#discussion_r4657820837
##########
airflow-core/tests/unit/api_fastapi/test_event_loop_blocking.py:
##########
@@ -158,6 +158,26 @@ def test_known_route_no_longer_blocks(self, test_client,
event_loop_queries, ent
method, path = route.split(" ", 1)
assert not _send_request(test_client, event_loop_queries, method,
path, mode)
+ @conf_vars({("core", "multi_team"): "True"})
+ @pytest.mark.parametrize(
+ ("url", "body"),
+ [
+ pytest.param("/api/v2/pools", {"name": "team_pool", "slots": 1},
id="pool"),
+ pytest.param(
+ "/api/v2/connections", {"connection_id": "team_conn",
"conn_type": "http"}, id="connection"
+ ),
+ pytest.param("/api/v2/variables", {"key": "team_var", "value":
"v"}, id="variable"),
+ ],
+ )
+ def test_team_lookup_runs_no_sync_sql_on_the_event_loop(
Review Comment:
This only covers POST. Could we add a PATCH on an existing resource with
`team_name`? That path runs both lookups.
##########
airflow-core/src/airflow/api_fastapi/core_api/security.py:
##########
@@ -1412,18 +1416,33 @@ def inner(
return inner
+# Request parameter identifying a team-scoped resource, and the columns to
read its team from.
+TEAM_SCOPED_RESOURCES = {
+ "pool_name": (Pool.team_name, Pool.pool),
+ "variable_key": (Variable.team_name, Variable.key),
+ "connection_id": (Connection.team_name, Connection.conn_id),
+}
+
+
async def _collect_teams_to_check(
method: ResourceMethod,
request: Request,
- resource_id: str | None,
- get_existing_team: Callable[[str], str | None],
+ resource_param: str,
+ *,
+ session: AsyncSession,
Review Comment:
On `GET /pools/{pool_name}`, this session now holds an async connection
until the sync handler returns. Write routes already do this through the audit
log, but GET routes have no audit log.
Could we open a short session here instead, as `execution_api/security.py`
does? Placing it after the multi_team check also skips the session when the
flag is off.
```python
if not conf.getboolean("core", "multi_team"):
return {None}
async with create_session_async() as session:
...
```
--
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]