Repository navigation
fix(org): replace the mappings of each project in an uploaded file - #9453
Open
henry-rystic wants to merge 2 commits into
Open
henry-rystic wants to merge 2 commits into
henry-rystic wants to merge 2 commits 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>
An upload of project_mapping.csv only added and updated rows. A mapping that was not in the new file stayed in the table, so a project kept data scopes that the user removed. Delete the mappings of the projects named in the file, then save the file, in the store's one transaction. Mappings of other projects do not change, because blueprints also write this table. Reject a file with an empty field, which usually means a wrong header, before it deletes anything. Closes apache#9449 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
An upload of
project_mapping.csvadds and updates rows, but it never removes rows. If a mapping is not in the new file, it stays inproject_mapping. So a project keeps data scopes that the user removed.Cause:
CreateProjectMappinginbackend/plugins/org/api/project_mapping.gosaves the rows without deleting first.project_name, then save (backend/plugins/org/tasks/project_mapping.go).This PR builds on #9451 (the fix for #9447), which adds
replaceto the org store. Please merge that PR first. Until then, this PR also shows its commit.Fix:
replace, in one transaction. If the save fails, the old mappings stay.ProjectName,TableorRowId. This usually means a wrong header, for exampleRowID. Without this check, such a file would delete the real mappings of a project.savemethod is removed, because nothing uses it now.Does this close any open issues?
Closes #9449
Screenshots
N/A
Other Information
Tests added:
backend/plugins/org/api/project_mapping_test.go(unit tests, with a fake store):TestCheckProjectMappings: empty and blank fields, and the row number in the error.TestProjectMappingDeletions: each project name once, in file order, and 1000 names in each statement.TestCreateProjectMapping: a valid file is passed to the store; a wrong header is rejected before the store is called; an error from the store is returned.backend/plugins/org/e2e/project_mapping_upload_test.go(with a database, CSV files ine2e/raw_tables/andVerifyTableagainste2e/snapshot_tables/). Each test first adds a mapping for another project, as a blueprint does.TestProjectMappingUploadReplacesProjectsInFile: upload three rows forPayments, then two.Paymentsmust have two rows, and the other project must not change.TestProjectMappingUploadFailureKeepsMappings: an upload with aRowIdof 300 characters must return an error and keep the old mappings.TestProjectMappingUploadAcceptsDuplicateRows: the same row twice in one file. PostgreSQL rejects an upsert that writes one key twice.BatchSaveremoves the duplicate, so this test makes sure that the upload keeps saving through it.Without the fix,
TestProjectMappingUploadReplacesProjectsInFilefails on MySQL and on PostgreSQL:Paymentskeeps three rows. With the fix, all tests pass on MySQL 8.4 and PostgreSQL 17.go vetpasses.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. Before step 1, I added one mapping for another project,Other, as a blueprint would.PUT /plugins/org/project_mapping.csvwith three rows forPayments(github:GithubRepo:1:7301,jira:JiraBoard:1:7302,github:GithubRepo:1:7303).GET /plugins/org/project_mapping.csv.Paymentsrows are listed.Payments.Otherin the tableThis PR was prepared with AI assistance (Claude Code). The commits carry a
Co-Authored-By:trailer.🤖 Generated with Claude Code