payloadcms/payload · error · APIError

Could not publish or save changes: One or more children are

Error message

Could not publish or save changes: One or more children are invalid.

What it means

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.

Source

Thrown at packages/plugin-nested-docs/src/hooks/resaveChildren.ts:95

              generateLabel: pluginConfig.generateLabel,
              generateURL: pluginConfig.generateURL,
              parentFieldName: pluginConfig.parentFieldSlug,
              req,
            }),
            depth: 0,
            draft: isDraft,
            locale: req.locale,
            req,
          })
        }
      } catch (err: unknown) {
        req.payload.logger.error(
          `Nested Docs plugin encountered an error while re-saving a child document.`,
        )
        req.payload.logger.error(err)

        if (err instanceof ValidationError && err.data?.errors?.length) {
          throw new APIError(
            'Could not publish or save changes: One or more children are invalid.',
            400,
          )
        }
      }
    }

    return undefined
  }

View on GitHub (pinned to 00c58b35c0)

Solutions

  1. Inspect `req.payload.logger.error(err)` output — the original `ValidationError.data.errors` lists which child and which field failed
  2. Fix the offending child document's data directly (fill the now-required field, resolve the slug collision) and re-trigger the parent save
  3. If a migration introduced the constraint, run a backfill on existing children before changing the parent
  4. Temporarily disable the offending validation hook to locate the child, then re-enable

Example fix

// before — required field added, old draft children lack it
fields: [{ name: 'slug', type: 'text', required: true, unique: true }]
// after — backfill first, then parent save succeeds
await payload.update({ collection: 'pages', id: childId, data: { slug: generatedUniqueSlug } })
Defensive patterns

Strategy: try-catch

Validate before calling

// Before reparenting, dry-validate affected children against current schema
for (const child of await findChildren(parentId)) {
  const r = childSchema.safeAwait?.(child) // or run a no-commit update in a transaction
  // surface any field that will fail before changing the parent
}

Type guard

import { APIError } from 'payload'
function isNestedDocsChildError(e: unknown): e is APIError {
  return e instanceof APIError && e.statusCode === 400
    && /One or more children are invalid/.test(e.message)
}

Try / catch

import { APIError } from 'payload'
try {
  await payload.update({ collection: 'pages', id, data: { parent: newParent } })
} catch (e) {
  if (e instanceof APIError && e.statusCode === 400 && /One or more children are invalid/.test(e.message)) {
    // inspect server logs (req.payload.logger.error output) for the child + field, fix it, then retry
  }
  throw e
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of payloadcms/payload@00c58b35c0 (2026-08-12). Data as JSON: /api/errors/17498ece17eef5c7. Report an issue: GitHub.