fix(V2): convert CSV batch upload staged data to snake_case - #1579
Open
TheLastCicada wants to merge 1 commit into
Open
fix(V2): convert CSV batch upload staged data to snake_case#1579TheLastCicada wants to merge 1 commit into
TheLastCicada wants to merge 1 commit into
Conversation
The V2 CSV batch upload endpoints for projects and units were staging data with camelCase field names (from CSV headers), but the V2 commit pipeline expects snake_case. This caused commits to fail because the primary key field (e.g. cad_trust_project_id) could not be found in the staged data headers. - Reuse toDbFieldNames() from v2-xls.js to convert CSV records to snake_case before staging, matching the XLSX upload path - Inject org_uid into staged records (consistent with XLSX path) - Hoist getHomeOrg() call before the CSV stream loop (once per batch instead of once per row) - Reuse UnitV2.prepareXlsRow() for serial ID derivation instead of duplicating the logic inline - Add integration tests verifying staged data format (snake_case fields, org_uid presence, primary key correctness) - Add tests for array field parsing (pipe-separated, JSON), error cases (non-existent ID, empty CSV), and serial ID derivation - Update V2 API docs to clarify CSV batch create/update behavior and document that NEW-<n> placeholders are XLSX-only
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
POST /v2/project/batchandPOST /v2/unit/batch) was staging data with camelCase field names from CSV headers, but the V2 commit pipeline expects snake_case. This caused commits to fail with a null primary key error becausecad_trust_project_idcould not be found in the camelCase header row.org_uid, which the XLSX upload path correctly injects. This could causeSequelizeUniqueConstraintErrorduring sync.NEW-<n>placeholder IDs are XLSX-only (not supported in CSV).Changes
src/utils/v2-xls.jstoDbFieldNames()for reusesrc/models/v2/project-v2.model.jstoDbFieldNames(), injectorg_uid, hoistgetHomeOrg()out of per-row loopsrc/models/v2/unit-v2.model.jsUnitV2.prepareXlsRow()instead of duplicating serial ID logicdocs/cadt_rpc_api_v2.mdNEW-<n>is XLSX-onlytests/v2/integration/project-v2.spec.jstests/v2/integration/unit-v2.spec.jsTest plan
org_uidis present in staged recordsuuidmatches the generated primary keyNote
Medium Risk
Changes how
POST /v2/project/batchandPOST /v2/unit/batchstage data for the commit pipeline (field naming, primary keys, org scoping), which can impact imports and downstream syncing if incorrect.Overview
Fixes V2 CSV batch upload staging for
projectandunitso staged JSON uses snake_case DB column names, includesorg_uidfrom the home org, and sets staginguuidto the effective primary key (generated on INSERT or provided on UPDATE). It also reuses existing XLSX-row preparation for units (includingunitSerialIdderivation) and exportstoDbFieldNames()for shared CSV/XLSX field conversion.Updates the API docs to clarify create-vs-update behavior for CSV uploads and that
NEW-<n>placeholders are XLSX-only, and expands integration tests to assert staging format, array parsing (pipe/JSON), serial derivation, and correct 400s for empty CSVs or non-existent IDs.Reviewed by Cursor Bugbot for commit 8a6bc0d. Bugbot is set up for automated code reviews on this repo. Configure here.