Repository navigation
fix(org): make a failed CSV upload change nothing - #9451
Open
henry-rystic wants to merge 1 commit into
Open
henry-rystic wants to merge 1 commit into
henry-rystic wants to merge 1 commit into
Conversation
A failed write in a teams, users or account mapping upload returned success, because the error from Close was ignored. The handler had already deleted all rows, so the table was left empty. The divider was shared for the life of the store, so its saved error then blocked every later upload of the same type. Run the delete and the save in one transaction with TxHelper, use a new divider for each upload, and return the error from Close. Closes apache#9447 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Signed-off-by: Henry Starman <334243260+henry-rystic@users.noreply.github.com>
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.
Summary
A failed CSV upload in the org plugin returns success and deletes all rows. After that, every upload of the same type fails until DevLake restarts. This affects
teams.csv,users.csvanduser_account_mapping.csv.Cause:
dbStore.save.savewrites the rows when it callsClose(), but it ignores the error fromClose(). So a failed write returns success, and the table is empty.dbStorekeeps oneBatchSaveDividerfor its whole life. The divider keeps oneBatchSaveper type, andBatchSavekeeps its last error. After one failed write,Addrejects every row withadd slot failed due to previous err.Fix:
replace. It runs the delete and the save in one transaction, withdbhelper.TxHelper. If any step fails, the transaction is rolled back, and nothing changes.replacecreates a newBatchSaveDividerfor each upload. So an error from one upload does not affect later uploads.replacereturns the error fromClose().Dal.savenow callsreplacewith no delete. Theproject_mapping.csvupload still usessave, so its write errors are now returned too.Does this close any open issues?
Closes #9447
Screenshots
N/A
Other Information
Tests added in
backend/plugins/org/e2e/csv_upload_test.go:TestCsvUploadFailureChangesNothing. It has one case for each upload: teams, users and user account mapping. It uses CSV files ine2e/raw_tables/and checks the tables withVerifyTableagainst files ine2e/snapshot_tables/. Each case does these steps:varchar(255), so MySQL in strict mode (the default) and PostgreSQL reject it. The upload must return an error, and the tables must not change.Without the fix, all three cases fail for the reasons in the issue, on MySQL and on PostgreSQL: step 2 returns no error, the tables are empty, and step 3 fails with
add slot failed due to previous err. With the fix, they pass.go test ./plugins/org/...passes on MySQL 8.4 and PostgreSQL 17, andgo vetpasses.The test calls the upload handlers, because the store methods are not exported. A test with a fake store would not test the bug, because the bug is in how the store uses the database.
Manual test. I built the backend image from this branch and ran it with MySQL 8.4. I ran the same steps on
apache/devlake:main_261124_0230_52d63a1to compare.PUT /plugins/org/teams.csvwith three teams.Namehas 300 characters.GET /plugins/org/teams.csvreturns only the header row. Theteamstable has 0 rows.Data too long for column 'name' at row 4. The three teams are still listed.add slot failed due to previous err. The table is still empty.PUT /plugins/org/users.csvwith one user.Note. When two uploads of the same type run at the same time on an empty table, MySQL can report a deadlock for one of them. That upload returns an error and changes nothing, so it can be sent again. Before this change, two uploads at the same time shared one divider, which was not safe.
The PR for #9449 builds on this PR. It uses
replaceto delete only the mappings of the projects in the file.This PR was prepared with AI assistance (Claude Code). The commit carries a
Co-Authored-By:trailer.🤖 Generated with Claude Code