{"record":{"id":"607f45b2aa94a151","repo":"payloadcms/payload","slug":"collection-is-not-a-hierarchy","errorCode":null,"errorMessage":"Collection is not a hierarchy","messagePattern":"Collection is not a hierarchy","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/ui/src/views/List/handleHierarchy.ts","lineNumber":47,"sourceCode":"}: {\n  baseFilter?: null | Where\n  collectionConfig: SanitizedCollectionConfig\n  collectionSlug: string\n  parentId: null | number | string\n  permissions?: SanitizedPermissions\n  req: PayloadRequest\n  search?: string\n  /** Filter hierarchy items by their collectionSpecific type field */\n  typeFilter?: string[]\n  user: PayloadRequest['user']\n}): Promise<HierarchyViewData> => {\n  const hierarchyConfig =\n    collectionConfig.hierarchy && typeof collectionConfig.hierarchy === 'object'\n      ? collectionConfig.hierarchy\n      : undefined\n\n  if (!hierarchyConfig) {\n    throw new Error('Collection is not a hierarchy')\n  }\n\n  const parentFieldName = hierarchyConfig.parentFieldName\n\n  const useAsTitle = collectionConfig.admin?.useAsTitle || 'id'\n\n  // Fetch the parent item and breadcrumbs (skip for root level)\n  let parent: null | (Record<string, unknown> & TypeWithID) = null\n  let breadcrumbs: Array<{ id: number | string; title: string }> = []\n\n  if (parentId !== null) {\n    try {\n      const [item, ancestors] = await Promise.all([\n        req.payload.findByID({\n          id: parentId,\n          collection: collectionSlug,\n          depth: 0,\n          overrideAccess: false,","sourceCodeStart":29,"sourceCodeEnd":65,"githubUrl":"https://github.com/payloadcms/payload/blob/00c58b35c0ed348ddc22daabf467b139727214fd/packages/ui/src/views/List/handleHierarchy.ts#L29-L65","documentation":"Thrown by handleHierarchy (the List view's hierarchy data loader) when the collection's sanitized config has no `hierarchy` object. This guard prevents the List view from issuing parent/breadcrumb/children queries against a collection that was never configured as a hierarchy. It is the view-layer counterpart of the getHierarchyAncestry guard.","triggerScenarios":"`viewType === 'hierarchy'` requested for a non-hierarchy collection; the `hierarchy` config removed but the view still routed there; custom routing that forces the hierarchy branch; a parent query param present on a non-hierarchy collection.","commonSituations":"Disabling hierarchy on a collection without updating the List routing, slug renames that orphan hierarchy routing, custom List overrides entering the hierarchy branch unconditionally.","solutions":["Enable `hierarchy` config on the collection (`hierarchy: { parentFieldName, ... }`).","Ensure the List view only enters the hierarchy branch for collections where `config.hierarchy` is an object.","Update routing so non-hierarchy collections never resolve to `viewType: 'hierarchy'`.","If hierarchy was intentionally removed, clear stale `parent` query params that trigger the hierarchy branch."],"exampleFix":"// before: 'folders' has no hierarchy config but is routed to hierarchy view\n\n// after: declare hierarchy on the collection\n// export const Folders = {\n//   slug: 'folders',\n//   hierarchy: { parentFieldName: 'parent' },\n//   fields: [{ name: 'parent', type: 'relationship', relationTo: 'folders' }],\n// }","handlingStrategy":"type-guard","validationCode":"if (\n  !collectionConfig.hierarchy ||\n  typeof collectionConfig.hierarchy !== 'object'\n) {\n  // not a hierarchy - do not enter the hierarchy branch of the List view\n}","typeGuard":"function isHierarchyCollection(\n  cfg: unknown,\n): cfg is { hierarchy: Record<string, unknown> } {\n  return (\n    !!cfg &&\n    typeof cfg === 'object' &&\n    'hierarchy' in cfg &&\n    typeof (cfg as { hierarchy: unknown }).hierarchy === 'object' &&\n    (cfg as { hierarchy: unknown }).hierarchy !== null\n  )\n}\n\n// usage in routing:\n// const isHierarchyView = viewType === 'hierarchy' && isHierarchyCollection(collectionConfig)\n// if (isHierarchyView) { await handleHierarchy(...) }","tryCatchPattern":null,"preventionTips":["Enter the hierarchy List branch only when `config.hierarchy` is an object.","Derive hierarchy-capable collection slugs from config and share them across routing/navigation.","When removing hierarchy from a collection, clear stale `parent` query params that route into the hierarchy view.","Add a route guard so a non-hierarchy collection can never resolve to `viewType: 'hierarchy'`."],"tags":["hierarchy","list-view","config","validation"],"backgroundTag":null,"analyzedSha":"00c58b35c0ed348ddc22daabf467b139727214fd","analyzedAt":"2026-08-12T20:45:03.758Z","schemaVersion":2},"datasetVersion":"2026-08-12T23:17:12.415Z"}