-
Notifications
You must be signed in to change notification settings - Fork 3.2k
fix(ingest/airflow): Fix DataHub Airflow Plugin Preventing TaskInstanceHistory Records #14723
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
treff7es
wants to merge
2
commits into
master
Choose a base branch
from
airflow_session_fix
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Conversation
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
❌ 10 Tests Failed:
View the top 3 failed test(s) by shortest run time
To view more test analytics, go to the Test Analytics Dashboard |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Labels
ingestion
PR or Issue related to the ingestion of metadata
needs-review
Label for PRs that need review from a maintainer.
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.
The DataHub Airflow plugin is preventing task instance history records from being saved to Airflow's database for failed tasks that get retried in Airflow 2.10.5. This causes task retries to not appear in the main Airflow UI, which relies on these history records.
Symptoms:
RuntimeError("UNEXPECTED COMMIT - THIS WILL BREAK HA LOCKS!")
Root Cause
The issue is caused by database session sharing between Airflow's internal operations and the DataHub plugin listener hooks.
When Airflow calls listener hooks like on_task_instance_failed(), it passes a SQLAlchemy session parameter that provides direct access to Airflow's active database session. The DataHub plugin
receiving this session object can cause transaction interference with Airflow's strict transaction boundaries, preventing TaskInstanceHistory.record_ti() from committing successfully.
In threaded mode: Session passed to worker threads causes cross-thread database access issues.
In non-threaded mode: Plugin runs synchronously and accessing the shared session triggers Airflow's HA lock protection errors.
Solution
This PR implements type-based SQLAlchemy session filtering in the run_in_thread decorator to prevent the DataHub plugin from accessing Airflow's database session context.
Key Changes
Before (problematic):
def safe_execution(*args, **kwargs):
# Plugin receives and can access Airflow's session
f(*args, **kwargs) # session parameter passed through
After (fixed):
def safe_execution(*args, **kwargs):
from sqlalchemy.orm import Session
Why This Works
Safety Analysis
What the plugin still receives (needed for functionality):
What gets filtered out (causes conflicts):
The DataHub plugin doesn't perform direct SQL operations requiring Airflow's session - it only needs metadata from the task/DAG objects for DataHub API calls.
Testing
Expected Impact
After this fix:
References