[medium] fix: csv feed with header=true imports zero attributes - #389
Merged
Merged
Conversation
fetch_csv_feed incremented `index` as the last statement of the loop body, but the header branch `continue`d before reaching it. With csvConfig.header enabled, `index` stayed 0 for every row, so the guard matched forever and the feed imported nothing while still reporting success. Drive the row counter with enumerate() and drop the manual increment, so the guard matches the first row only. Adds a regression test for both the header and the no-header case. Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #389 +/- ##
==========================================
+ Coverage 84.40% 84.56% +0.16%
==========================================
Files 208 209 +1
Lines 19402 19425 +23
==========================================
+ Hits 16376 16427 +51
+ Misses 3026 2998 -28 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Collaborator
|
Good catch, thanks! |
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.
BLUF
fetch_csv_feed, the header-skip branchcontinues before theindex += 1at the bottom of the loop body, soindexnever leaves0.csvConfig.headertrue skips all its rows and imports nothing — run after run, while still reporting"result": "success".enumerate(rows)and drop the manual increment, so the guard matches the first row only.api/app/worker/tasks.py, plus one new mock-only test module. No API schema change, sodocs/features/api/openapi.jsonis untouched.What was wrong
api/app/worker/tasks.pyinitialisesindex = 0before the ingestion loop and increments it as the last statement of the loop body:When
csvConfig.headeris true, the guard fires on the first iteration andcontinuejumps straight back to thefor, never reachingindex += 1.indextherefore stays0for every subsequent row and the guard fires forever.The header is not stripped anywhere upstream either:
feeds_repository.parse_csv_feed_linessimply runscsv.readerover the lines and returns every parsed row, so this guard is the only header handling in the CSV ingestion path.Concrete impact
A CSV feed configured with a header line imports zero attributes on every fetch. Because the exceptions counter is never reached either, the task still returns:
There is no error, no failed row and no log line — the feed just looks empty, indefinitely.
What this changes
for row in rows:becomesfor index, row in enumerate(rows):.index = 0initialiser and the trailingindex += 1are removed;enumeratenow owns the counter.Nothing else in the function reads
index, and feeds without a header behave exactly as before.How it was verified
api/app/tests/services/test_feed_worker_tasks.py, following the mock-based style of the existingtest_correlation_worker_tasks.py(no service containers needed):test_skips_the_header_row_only— 3 CSV lines withheader=true. On unpatchedmainit reports0 rows parsed, 0 attributes created; with the fix it reports2 rows parsed, 2 attributes created, 0 rows failedand assertsprocess_csv_feed_rowis called with the two data rows and never with the header row.test_keeps_every_row_when_there_is_no_header— same feed withheader=false, asserting all 3 rows are still ingested, so a future fix cannot over-skip.cd api && poetry run pytest app/tests/services/test_feed_worker_tasks.py.Local verification
Output: