vincbeck commented on code in PR #77599:
URL: https://github.com/apache/airflow/pull/77599#discussion_r4700002882
##########
providers/fab/src/airflow/providers/fab/auth_manager/fab_auth_manager.py:
##########
@@ -473,7 +472,8 @@ def build_public_user(self, *, session: Session =
NEW_SESSION) -> AnonymousUser
return None
user = AnonymousUser()
- role = session.scalar(select(Role).where(Role.name ==
public_role_name))
+ async with create_session_async() as session:
Review Comment:
This breaks
`test_legacy_auth_role_public_grants_its_role_to_anonymous_requests` in
`test_public_access.py` on MySQL (that's the red CI job). `run_api_server`
returns a `TestClient` without `with`, so each request runs in its own event
loop. The second request reuses the asyncmy connection pooled by the first one,
whose loop is already closed, and gets a 500. Fix: use `with TestClient(...) as
client:` in `run_api_server` so all requests share one loop.
##########
providers/fab/tests/unit/fab/auth_manager/test_fab_auth_manager.py:
##########
@@ -608,14 +612,33 @@ def
test_build_public_user_with_unknown_role_returns_user_with_empty_perms(
previous = flask_app.config.get("AUTH_ROLE_PUBLIC")
flask_app.config["AUTH_ROLE_PUBLIC"] = "DoesNotExist"
try:
- user = auth_manager_with_appbuilder.build_public_user()
+ user = await auth_manager_with_appbuilder.build_public_user()
finally:
flask_app.config["AUTH_ROLE_PUBLIC"] = previous
assert isinstance(user, AnonymousUser)
# Role not found in the DB, so no pre-populated perms.
assert user._perms == set()
+ @pytest.mark.asyncio
+ async def test_build_public_user_does_not_use_sync_engine(self,
auth_manager_with_appbuilder):
+ """The public role lookup must not run on a sync engine (it would
block the event loop)."""
+ sync_statements = []
+
+ def record_sync_statement(conn, cursor, statement, parameters,
context, executemany):
+ if not conn.dialect.is_async:
+ sync_statements.append(statement)
+
+ event.listen(Engine, "before_cursor_execute", record_sync_statement)
+ try:
+ with conf_vars({("fab", "auth_role_public"): "Admin"}):
Review Comment:
nit: the value is fixed, so `conf_vars` should be a decorator on the test
--
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]