Commit 6ed3c0d
authored
fix: Robust and Idempotent Backfill for Search Pipeline Run API (#166)
### TL;DR
Refactored database migration logic to ensure data parity by creating system annotations for all pipeline runs, even when source values are null or empty, and moved backfill functions to a dedicated module with comprehensive error handling.
### What changed?
- **System annotation mirroring now ensures data parity**: The `_mirror_system_annotations` function always creates annotation rows for `created_by` and `pipeline_name`, storing empty string `""` when source values are null/empty, with warning logs for null cases
- **New dedicated migration module**: Created `database_migrate.py` containing three idempotent backfill functions:
- `backfill_created_by_annotations`: Uses `COALESCE` to handle null values
- `backfill_pipeline_names_from_extra_data`: Extracts from JSON with null filtering
- `backfill_pipeline_names_from_component_spec`: Extracts from nested JSON path with anti-join logic
- **Robust orchestration**: `run_all_annotation_backfills` wraps all backfills in try-catch with configurable skip guards and single transaction commit
- **Enhanced test coverage**: Added 1600+ lines of comprehensive tests covering idempotency, order independence, data parity, error handling, and edge cases
- **Updated existing tests**: Modified assertions to expect empty string annotations instead of missing keys
### How to test?
Run the existing test suite - the new `test_database_migrate.py` provides extensive coverage including:
- Basic backfill functionality for both sources
- Idempotency verification (safe to run multiple times)
- Order independence between pipeline name sources
- Data parity validation (every run gets annotations)
- Error handling and transaction rollback scenarios
- Truncation behavior for long values
### Why make this change?
- **Data consistency**: Ensures every pipeline run has system annotations for reliable filtering/querying, eliminating gaps where some runs lack annotation rows
- **Improved maintainability**: Separates migration logic from general database operations with better organization and comprehensive documentation
- **Production reliability**: Adds proper error handling so migration failures don't block application startup, with detailed logging for debugging
- **Database portability**: Uses SQLAlchemy abstractions for cross-database compatibility (SQLite, MySQL, PostgreSQL)1 parent ce2c295 commit 6ed3c0d
7 files changed
Lines changed: 2762 additions & 1394 deletions
File tree
- cloud_pipelines_backend
- tests
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
42 | 43 | | |
43 | 44 | | |
44 | 45 | | |
45 | 46 | | |
46 | 47 | | |
47 | 48 | | |
48 | | - | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
49 | 52 | | |
50 | 53 | | |
51 | 54 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1331 | 1331 | | |
1332 | 1332 | | |
1333 | 1333 | | |
1334 | | - | |
| 1334 | + | |
| 1335 | + | |
| 1336 | + | |
| 1337 | + | |
| 1338 | + | |
| 1339 | + | |
1335 | 1340 | | |
1336 | 1341 | | |
1337 | 1342 | | |
1338 | 1343 | | |
1339 | 1344 | | |
1340 | 1345 | | |
1341 | 1346 | | |
1342 | | - | |
1343 | | - | |
1344 | | - | |
1345 | | - | |
| 1347 | + | |
| 1348 | + | |
| 1349 | + | |
| 1350 | + | |
| 1351 | + | |
| 1352 | + | |
| 1353 | + | |
| 1354 | + | |
| 1355 | + | |
| 1356 | + | |
| 1357 | + | |
| 1358 | + | |
| 1359 | + | |
| 1360 | + | |
| 1361 | + | |
| 1362 | + | |
1346 | 1363 | | |
| 1364 | + | |
| 1365 | + | |
1347 | 1366 | | |
1348 | | - | |
1349 | | - | |
1350 | | - | |
1351 | | - | |
1352 | | - | |
1353 | | - | |
| 1367 | + | |
| 1368 | + | |
| 1369 | + | |
| 1370 | + | |
| 1371 | + | |
| 1372 | + | |
| 1373 | + | |
| 1374 | + | |
1354 | 1375 | | |
1355 | | - | |
1356 | | - | |
1357 | | - | |
1358 | | - | |
| 1376 | + | |
| 1377 | + | |
| 1378 | + | |
| 1379 | + | |
| 1380 | + | |
| 1381 | + | |
| 1382 | + | |
| 1383 | + | |
| 1384 | + | |
1359 | 1385 | | |
| 1386 | + | |
| 1387 | + | |
1360 | 1388 | | |
1361 | | - | |
1362 | | - | |
1363 | | - | |
1364 | | - | |
1365 | | - | |
1366 | | - | |
1367 | | - | |
| 1389 | + | |
1368 | 1390 | | |
1369 | 1391 | | |
1370 | 1392 | | |
| |||
0 commit comments