ChickenBenny commented on code in PR #77599:
URL: https://github.com/apache/airflow/pull/77599#discussion_r4705543593


##########
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:
   I kept the context manager here because the test is `async`. `conf_vars` is 
a `contextlib.contextmanager`, so as a decorator it only wraps the call that 
creates the coroutine, and the override is gone by the time the test body runs. 
I checked it: inside an `async def` decorated with `@conf_vars`, 
`conf.get("fab", "auth_role_public")` returns `''`.



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