Repository navigation
fix(plugin-import-export): drop empty schema columns of fields collapsed by beforeExport hooks - #19185
fix(plugin-import-export): drop empty schema columns of fields collapsed by beforeExport hooks#19185sarankumar1325 wants to merge 1 commit into
Conversation
…sed by beforeExport hooks
|
No actionable comments were generated in the recent review.
|
| Layer / File(s) | Summary |
|---|---|
Parent column replacement packages/plugin-import-export/src/utilities/getSchemaColumns.ts, packages/plugin-import-export/src/utilities/getSchemaColumns.spec.ts |
When data contains a parent column and none of its matching schema child columns, mergeColumns inserts the parent and removes the children. Tests cover array, group, and relationship columns, and verify array-column ordering. |
Priority:
Estimated code review effort: 2 (Simple) | ~10 minutes
Change: Bug fix · Severity of issue fixed: Medium
Possibly related PRs
- payloadcms/payload#19144: Both changes affect streamed CSV column resolution. This PR changes how shared column merging handles a data column that replaces schema child columns.
Suggested reviewers: paulpopus
Merge Risk: 
Low · up to 44d94
-
An unrelated empty CSV header can disappear when its field shares a prefix with a collapsed field. The change is mergeable with awareness of that limitation.
Security architecture risk: 
Low · up to 44d94
-
The change is confined to export column selection and does not expand permissions or document access. However, streaming exports can silently omit later child values when a field hook initially collapses a field and subsequently falls back to normal flattening.
Retained concerns
- Medium · reliability · inferred: Streaming CSV can discard field-hook recovery output. Without a collection-level before hook, a first batch containing only a collapsed parent now removes its schema children from the finalized header. If a later field-level hook throws, the existing fallback emits those child values, but row padding copies only finalized columns and silently drops them. The base retained these schema children. This weakens the existing per-row hook-failure containment contract.
Security review details
-
Security Blast Radius
- inferred — The demonstrated impact is confined to columns in existing export and preview outputs. The changed utility operates after document retrieval and field transformation; the inspected change does not introduce broader collection access or additional identity authority.
Resilience and Maintainability Implications
- observed — Field-hook exceptions are logged and recover through default flattening. Separately, collection-level before hooks already filter first-batch columns to observed keys, so omissions under that control predate this PR. The introduced recovery concern applies where field-level hooks previously retained schema children.
Pre-merge checks: 
5
-
Full details: Linked Issues check
-
Explanation
Issue
#19141requires removal of empty array schema columns when a field-levelbeforeExporthook emits one value.mergeColumnsnow detects a data column such astagswhen schema columns such astags_0_labelandtags_0_idare absent from the data, insertstagsin their position, and removes the empty child columns. Tests cover the array case and verify that normal array exports and existing relationship replacement remain unchanged.
Full details: Out of Scope Changes check
-
Explanation
The changes are limited to
mergeColumnsand its unit tests. The group-field test verifies the same collapse behavior, and the regression tests support the modified column-merging logic. No unrelated production or test changes are present.
Full details: Docstring Coverage
-
Explanation
No eligible functions found in the changed files. Skipping docstring coverage check. Docstring coverage is scoped to functions touched by this diff with cyclomatic complexity of at least 2. Documentation-only edits and deletions within surviving functions are included; unchanged diff context and fully deleted functions are excluded. Analyzed 0 functions across 2 files.
-
Finishing Touches
-
🧪 Generate unit tests (beta)
-
- Create a new PR
-
- Autofix · Keep fixing CodeRabbit findings and required CI, and resolving merge conflicts
Comment @coderabbitai help to get the list of available commands.
What?
When a field-level
beforeExporthook turns an array (or group) field into a single value, the CSV header no longer keeps that field's schema columns. Before this change, a hook ontagsthat returns"x | y"produced the header...,tags_0_label,tags_0_id,updatedAt,tags,createdAt, withtags_0_*empty in every row.Why?
mergeColumnsstarts from the schema columns, which always includetags_0_*for an array, and then adds the data columns. The newtagscolumn was appended beforecreatedAt, and nothing removed thetags_0_*columns that the hook had replaced. The existing cleanup only handled the opposite case, where a schema column likeuseris replaced by derived columns such asuser_id.How?
In
mergeColumns, when a data column isn't in the schema but some schema columns start with<column>_, and none of those schema columns show up in the data, the derived column takes the place of those schema columns. If any of the child columns are still in the data, nothing changes, so normal array exports and theusertouser_idcase behave the same as before.Added
mergeColumnsunit tests togetSchemaColumns.spec.ts. The array and group cases fail without the fix and pass with it. The other two cases are regression checks for normal arrays and theusertouser_idreplacement. I ran the spec in a standalone vitest setup, without the full monorepo install, and the file is formatted with oxfmt.Fixes #19141
This PR was prepared with help from an AI coding assistant. I reviewed and tested the change.