fix: populate results_sample when dbt sample_data is dict-shaped#2271
fix: populate results_sample when dbt sample_data is dict-shaped#2271orenniapete wants to merge 1 commit into
Conversation
Some dbt-core / elementary-dbt-package version combinations return
sample rows wrapped in a dict (e.g. {"rows": [...]}) instead of as a
bare list. The previous code used a hard cast to list which silently
left results_sample empty, so the EDR report showed failure counts but
no example rows.
Fix: add TestsAPI._normalize_results_sample() that accepts both shapes
and extract the rows list from common dict wrapper keys (rows,
sample_rows, results_sample, data). The fix is backward-compatible –
list payloads pass through unchanged and disable_samples is still
respected.
Tests:
- Unit tests for _normalize_results_sample with list, dict (all keys),
None, and unknown dict
- Unit tests for _get_test_result_from_test_result_db_row covering list
sample, dict sample, None sample, and disable_samples suppression
- Integration test through get_test_results() verifying the full
serialization path populates results_sample from both payload shapes
Fixes elementary-data#2269
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughThis PR fixes issue ChangesSample Data Normalization
Estimated code review effort🎯 2 (Simple) | ⏱️ ~12 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Warning Review ran into problems🔥 ProblemsGit: Failed to clone repository. Please run the Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Fixes #2269
Problem
The EDR report shows failure row counts but no example rows for
dbt_testfailures, even though rows exist indbt_test__auditandtest_result_rows.Root cause
TestsAPI._get_test_result_from_test_result_db_rowhard-castsample_datatolist. Some dbt-core / elementary-dbt-package version combinations (confirmed with dbt-core 1.11.5 + elementary 0.22.0 vs 0.24.0) return sample rows wrapped in a dict such as{"rows": [...]}instead of as a bare list. The cast silently producedNone, leavingresults_sampleempty in the serialized report payload, so the report UI had nothing to render.Fix
Added
TestsAPI._normalize_results_sample()which handles both payload shapes:rows,sample_rows,results_sample,data) → the rows list is extracteddisable_samplesis fully respected in both cases.Files changed
elementary/monitor/api/tests/tests.py_normalize_results_sample(); replace hardcast(list)with ittests/mocks/fetchers/tests_fetcher_mock.pysample_data, one with dictsample_datatests/unit/monitor/api/tests/test_tests_api.pyAll 15 tests in the file pass.
Summary by CodeRabbit
Bug Fixes
Tests