{"record":{"id":"17498ece17eef5c7","repo":"payloadcms/payload","slug":"could-not-publish-or-save-changes-one-or-more-chi","errorCode":null,"errorMessage":"Could not publish or save changes: One or more children are invalid.","messagePattern":"Could not publish or save changes: One or more children are invalid\\.","errorType":"http","errorClass":"APIError","httpStatus":400,"severity":"error","filePath":"packages/plugin-nested-docs/src/hooks/resaveChildren.ts","lineNumber":95,"sourceCode":"              generateLabel: pluginConfig.generateLabel,\n              generateURL: pluginConfig.generateURL,\n              parentFieldName: pluginConfig.parentFieldSlug,\n              req,\n            }),\n            depth: 0,\n            draft: isDraft,\n            locale: req.locale,\n            req,\n          })\n        }\n      } catch (err: unknown) {\n        req.payload.logger.error(\n          `Nested Docs plugin encountered an error while re-saving a child document.`,\n        )\n        req.payload.logger.error(err)\n\n        if (err instanceof ValidationError && err.data?.errors?.length) {\n          throw new APIError(\n            'Could not publish or save changes: One or more children are invalid.',\n            400,\n          )\n        }\n      }\n    }\n\n    return undefined\n  }\n","sourceCodeStart":77,"sourceCodeEnd":105,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/plugin-nested-docs/src/hooks/resaveChildren.ts#L77-L105","documentation":"Thrown by the nested-docs plugin's `resaveChildren` after-change hook when re-saving descendant documents (to refresh breadcrumbs after a parent change) and one of those `req.payload.update` calls raises a `ValidationError` with structured `data.errors`. The original validation details are logged but the user-facing APIError is a generic 400 — the children are invalid for the new breadcrumb/parent state.","triggerScenarios":"Moving or renaming a parent page such that a child's recomputed data fails a required-field or uniqueness validation on update; a child doc references fields that became invalid under the new parent; drafts enabled and a child draft's data violates a hook added after it was created.","commonSituations":"Adding a required field to a collection with pre-existing draft children that lack it; changing breadcrumb generation so a child's slug collides; a `beforeChange`/`beforeValidate` hook on the child that rejects the resaved payload; very large trees where one deep descendant is invalid.","solutions":["Inspect `req.payload.logger.error(err)` output — the original `ValidationError.data.errors` lists which child and which field failed","Fix the offending child document's data directly (fill the now-required field, resolve the slug collision) and re-trigger the parent save","If a migration introduced the constraint, run a backfill on existing children before changing the parent","Temporarily disable the offending validation hook to locate the child, then re-enable"],"exampleFix":"// before — required field added, old draft children lack it\nfields: [{ name: 'slug', type: 'text', required: true, unique: true }]\n// after — backfill first, then parent save succeeds\nawait payload.update({ collection: 'pages', id: childId, data: { slug: generatedUniqueSlug } })","handlingStrategy":"try-catch","validationCode":"// Before reparenting, dry-validate affected children against current schema\nfor (const child of await findChildren(parentId)) {\n  const r = childSchema.safeAwait?.(child) // or run a no-commit update in a transaction\n  // surface any field that will fail before changing the parent\n}","typeGuard":"import { APIError } from 'payload'\nfunction isNestedDocsChildError(e: unknown): e is APIError {\n  return e instanceof APIError && e.statusCode === 400\n    && /One or more children are invalid/.test(e.message)\n}","tryCatchPattern":"import { APIError } from 'payload'\ntry {\n  await payload.update({ collection: 'pages', id, data: { parent: newParent } })\n} catch (e) {\n  if (e instanceof APIError && e.statusCode === 400 && /One or more children are invalid/.test(e.message)) {\n    // inspect server logs (req.payload.logger.error output) for the child + field, fix it, then retry\n  }\n  throw e\n}","preventionTips":["Run backfills when adding required fields or uniqueness constraints to nested-docs collections","Keep breadcrumb/slug generators from producing collisions under reparenting","Log and surface the original `ValidationError.data.errors` server-side so the offending child is identifiable"],"tags":["nested-docs","breadcrumb","validation","drafts","tree"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}