{"record":{"id":"3d1140ca09cb406b","repo":"hcengineering/platform","slug":"create-step-must-have-space","errorCode":null,"errorMessage":"Create step must have space","messagePattern":"Create step must have space","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/tool/src/initializer.ts","lineNumber":314,"sourceCode":"        space === undefined ||\n        attachedToClass === undefined ||\n        collection === undefined\n      ) {\n        throw new Error('Add collection step must have attachedTo, attachedToClass, collection and space')\n      }\n      return (await this.client.addCollection(\n        _class,\n        space,\n        attachedTo,\n        attachedToClass,\n        collection,\n        props,\n        _id as Ref<AttachedDoc> | undefined\n      )) as unknown as Ref<T>\n    } else {\n      const { space, ...props } = data\n      if (space === undefined) {\n        throw new Error('Create step must have space')\n      }\n      return await this.client.createDoc<T>(_class, space, props as Data<T>, _id)\n    }\n  }\n\n  private async fillPropsWithMarkdown<T extends Doc, P extends Partial<T> | Props<T>>(\n    data: P,\n    vars: Record<string, any>,\n    markdownFields?: string[]\n  ): Promise<P> {\n    data = await this.fillProps(data, vars)\n    if (markdownFields !== undefined) {\n      for (const field of markdownFields) {\n        if ((data as any)[field] !== undefined) {\n          try {\n            const res = this.parseMarkdown((data as any)[field])\n            ;(data as any)[field] = res\n          } catch (error) {","sourceCodeStart":296,"sourceCodeEnd":332,"githubUrl":"https://github.com/hcengineering/platform/blob/63e28dc96483967b2fc21c881b3f1023c1de7718/server/tool/src/initializer.ts#L296-L332","documentation":"For regular document classes, create() destructures space out of the step data and requires it to create the doc via client.createDoc, since every Huly document must live in a space. If space is undefined after destructuring, the step data lacks a space and the method throws before attempting the document creation.","triggerScenarios":"Calling create() (via processCreate) for a non-attached doc class with data that has no space property, or where space is explicitly undefined (e.g. set from an unresolved variable).","commonSituations":"Import/migration data exported from a model version where docs were attached and didn't need space; dynamic step generation where the space value failed to resolve; forgetting to include space when hand-writing seed fixtures.","solutions":["Include a valid space value in the step data","Verify the space reference resolves (not undefined) before running the migration","If the doc should be attached instead, use the add-collection/attached branch which takes attachedTo instead"],"exampleFix":"// before\nawait initializer.create('contact:class:Contact', { name: 'John' } as any)\n// after\nawait initializer.create('contact:class:Contact', { space: defaultSpace, name: 'John' })","handlingStrategy":"validation","validationCode":"if (data == null || (data as any).space === undefined) {\n  throw new Error(`Create step for ${_class} is missing space`)\n}\nawait initializer.create(_class, data)","typeGuard":"function hasSpace<T extends { space?: Ref<Space> }>(d: T): d is T & { space: Ref<Space> } {\n  return d.space !== undefined\n}","tryCatchPattern":"try {\n  await initializer.create(_class, data)\n} catch (err) {\n  if (err instanceof Error && err.message === 'Create step must have space') {\n    console.error(`Step for ${_class} lacks space:`, data)\n  }\n  throw err\n}","preventionTips":["Make space a required property in your step/fixture types","Validate seed/migration data for a space field before running","When converting attached docs to plain docs, remember to add a space explicitly"],"tags":["validation","migration","initializer"],"backgroundTag":"missing-required-field","analyzedSha":"63e28dc96483967b2fc21c881b3f1023c1de7718","analyzedAt":"2026-08-29T15:21:27.377Z","schemaVersion":2},"datasetVersion":"2026-08-29T17:17:51.833Z"}