Fix AsyncToSync error in Databricks deferrable operators by fetching connection asynchronously - #71840
Open
saitejabandaru-in wants to merge 1 commit into
Conversation
This adds `adatabricks_conn` to `BaseDatabricksHook` to allow fetching the connection via TaskSDK asynchronously, resolving an issue where the async triggerer loop crashed when calling the synchronous `databricks_conn` property. All async methods have been refactored to use the async connection path. Fixes apache#71525.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #71525.
Motivation
When
DatabricksRunNowOperator(deferrable=True)is used, the triggerer executesDatabricksExecutionTrigger.run(). Inside the async loop, the trigger polls for status viaDatabricksHook.a_get_run_state(), which eventually callsself._endpoint_url(). That function tries to readself.databricks_conn, which is a@cached_propertyinvokingself.get_connection().In Airflow 3 (TaskSDK),
get_connectionbridges to a synchronous supervisor call usingasync_to_sync. Because this happens inside the triggerer's already-running asyncio loop, it crashes withRuntimeError: You cannot use AsyncToSync in the same thread as an async event loop.Changes
adatabricks_conntoBaseDatabricksHookwhich fetches the connection asynchronously viaaget_connection.ahost,_a_endpoint_url, and_a_get_oidc_token_service_urlto prevent async methods from callingself.host(which also evaluatesdatabricks_connsynchronously).async defmethods inBaseDatabricksHookto use(await self.adatabricks_conn())andawait self._a_endpoint_url().adatabricks_conn.