fix(plugin-import-export): respect defaultVersionStatus/draft on update-mode imports#17426
Open
jaccovdalfsen wants to merge 1 commit into
Open
Conversation
…te-mode imports processImportBatch never passed draft to payload.update() (or applied the defaultVersionStatus fallback) on the update-existing-doc path for importMode: 'update'/'upsert', so re-importing a versioned document always overwrote the published version live regardless of defaultVersionStatus or an incoming draft _status, since core's update operation only saves a draft when the draft argument is explicitly passed. Adds a regression test under the posts-imports-only suite (which already configures defaultVersionStatus: 'draft') asserting the published version is preserved and the update lands in a new draft version, plus published- version assertions on the existing upsert-mode test to cover the published default-status path.
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.
Problem
When importing into a collection with
versions.draftsenabled usingimportMode: 'update'or'upsert'against an existing document,processImportBatch(inpackages/plugin-import-export/src/import/batchProcessor.ts) never passeddrafttopayload.update(), and never applied the plugin'sdefaultVersionStatusfallback — that fallback only existed on the sibling create branch.Effect: re-importing a document (e.g. one exported without its
_statuscolumn) always overwrote the currently published version live, even whendefaultVersionStatus: 'draft'was configured, because Payload core'supdateoperation only saves a draft when thedraftargument is explicitly passed (isSavingDraft = Boolean(draftArg && ...)inpackages/payload/src/collections/operations/utilities/update.ts).Root cause
The
importMode === 'update' || importMode === 'upsert'branch's "existing document found" case builtupdateDatabut skipped the_status/draftOptionresolution that thecreatebranch (and the upsert-creates-new branch) already do, and never forwardeddraftto either of the tworeq.payload.update()calls that follow (the multi-locale branch and the non-multi-locale branch).Fix
Mirrors the existing create-mode logic: resolves
statusValue = updateData._status || options.defaultVersionStatus, derivesdraftOption, setsupdateData._status, and passesdraft: draftOptionto bothpayload.update()calls.Tests
posts-imports-onlydescribe block intest/plugin-import-export/int.spec.ts(that collection already configuresdefaultVersionStatus: 'draft'withversions.drafts: true). It creates a published doc, updates it via anupdate-mode import with a row that omits_status, and asserts the published version is untouched while a new draft version holds the updated data.should handle upsert mode correctlytest to cover the published-default-status path (pages has nodefaultVersionStatusoverride, so it should continue to publish directly — confirming no regression there).pnpm run test:int plugin-import-export) passes: 238 passed, 5 skipped, 0 failed.Test plan
pnpm run test:int plugin-import-exportpasses locally (MongoDB)tsc --noEmit/ build ofplugin-import-exportsucceeds_status-in-row behavior🤖 Generated with Claude Code