Repository navigation
Done
Description
Search before asking
- I had searched in the issues and found no similar issues.
What happened
There are two related problems in the CSV uploads of the org plugin (teams.csv, users.csv, user_account_mapping.csv).
Problem 1: a failed write returns success.
- Each handler first deletes all rows (
team.go:87,user.go:90and:94,user_account_mapping.go:80). Then it callsdbStore.save. - The batch size is 1000 (
store.go:45). For a normal file, the rows are written only whensavecallsd.driver.Close()(store.go:122). The error fromClose()is ignored. - So when the write fails, the API still returns
{"success":true}, and the table is empty. For example, the write fails when a value is longer than its column (MySQL strict mode is on by default).
Problem 2: after one failure, every later upload of the same type fails.
dbStoreuses oneBatchSaveDividerfor its whole life (store.go:45).ForTypekeeps oneBatchSaveper type in a cache.Closedoes not clear this cache.BatchSavekeeps the write error inlastErr(batch_save.go:133). After that,Addrejects every row withadd slot failed due to previous err(batch_save.go:90).- So every later upload of that type returns 500 until DevLake restarts. Each of these uploads also deletes the existing rows first.
What do you expect to happen
- When an upload fails, the API returns an error, and the existing rows do not change.
- A failed upload does not affect later uploads.
How to reproduce
Tested with the image apache/devlake:main_261124_0230_52d63a1 and MySQL 8.4.
- Send
PUT /plugins/org/teams.csvwith a file of three teams (headerId,Name,Alias,ParentId,SortingIndex). Result:{"success":true}.GET /plugins/org/teams.csvlists the three teams. - Send the same three teams and a fourth team whose
Namehas 300 characters. Result: 200{"success":true}.GET /plugins/org/teams.csvreturns only the header row, and theteamstable has 0 rows. The log showsError 1406 (22001): Data too long for column 'name' at row 4. - Send the file from step 1 again. Result: 500
add slot failed due to previous err ... Data too long for column 'name' at row 4. Theteamstable is still empty. - Restart DevLake and send the same file. Result: success. The three teams are back.
A users.csv upload between step 3 and step 4 works. Only the type that failed is blocked.
Anything else
It happens every time when MySQL strict mode is on (the default).
Possible fix: create a new divider for each upload, return the error from Close(), and run the delete and the save in one transaction.
Version
main (52d63a1)
Are you willing to submit PR?
- Yes I am willing to submit a PR!
Code of Conduct
- I agree to follow this project's Code of Conduct
Metadata
Metadata
Assignees
Labels
No labels
Activity
[-][Bug][Org] A failed teams/users upload reports success, empties the table, and breaks later uploads until restart[/-][+][Bug][Org] A failed teams or users CSV upload returns success, deletes all rows, and blocks later uploads[/+]fix(org): make a failed CSV upload change nothing