🚨 CRITICAL FIX: Race condition in shared resource manager#16
Draft
🚨 CRITICAL FIX: Race condition in shared resource manager#16
Conversation
🚨 CRITICAL BUG FIX: Race condition in SQLMeshResultsResource ## Problem The shared resource manager had a critical race condition where multiple assets could simultaneously: 1. Check has_results(run_id) → False 2. Decide to execute SQLMesh 3. Execute SQLMesh in parallel 4. Result: Multiple SQLMesh executions for the same run! ## Solution Implemented a robust solution using Dagster's native dependency system: ### ✅ New Architecture - **Precompute Asset**: sqlmesh_execution_results executes SQLMesh once per run - **Individual Assets**: Depend directly on the precompute asset via deps=[sqlmesh_execution_results] - **Native Dagster Flow**: No more race conditions, Dagster manages execution order - **Reused Existing Logic**: All console/notifier tracking preserved ### 🔧 Key Changes - Created sqlmesh_execution_results asset that executes SQLMesh once - Modified individual assets to depend on precompute results - Removed SQLMeshResultsResource (no longer needed) - Reused existing utilities: execute_sqlmesh_materialization, handle_successful_execution - Preserved all console custom and notifier logic for audit capture ### 🎯 Benefits - ✅ **Guaranteed Single Execution**: One SQLMesh run per Dagster run - ✅ **No Race Conditions**: Dagster manages dependencies natively - ✅ **Preserved Functionality**: All audit capture and model tracking works - ✅ **Better Debugging**: Clear execution flow in Dagster UI - ✅ **Simplified Architecture**: No complex shared state management ### 🧪 Testing - All 173 tests pass - Integration tests updated for new architecture - Backward compatibility maintained This fixes the fundamental architectural flaw that was causing multiple SQLMesh executions.
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.
🚨 CRITICAL BUG FIX: Race condition in SQLMeshResultsResource
Problem
The shared resource manager had a critical race condition where multiple assets could simultaneously:
has_results(run_id)→FalseSolution
Implemented a robust solution using Dagster's native dependency system:
✅ New Architecture
sqlmesh_execution_resultsexecutes SQLMesh once per rundeps=[sqlmesh_execution_results]🔧 Key Changes
sqlmesh_execution_resultsasset that executes SQLMesh onceSQLMeshResultsResource(no longer needed)execute_sqlmesh_materialization,handle_successful_execution🎯 Benefits
🧪 Testing
This fixes the fundamental architectural flaw that was causing multiple SQLMesh executions.
Files Changed
src/dg_sqlmesh/factory.py- New precompute asset architecturetests/integration/test_asset_execution.py- Updated tests for new architectureBreaking Changes
SQLMeshResultsResourceis no longer used (removed from resources)sqlmesh_execution_resultsassetMigration
No migration needed - the change is backward compatible at the API level.