{"record":{"id":"36300caf99fc1a37","repo":"octobercms/october","slug":"cannot-extend-an-empty-model","errorCode":null,"errorMessage":"Cannot extend an empty model.","messagePattern":"Cannot extend an empty model\\.","errorType":"exception","errorClass":"SystemException","httpStatus":null,"severity":"error","filePath":"modules/tailor/classes/Fieldset.php","lineNumber":73,"sourceCode":"    }\n\n    /**\n     * validate all the fields\n     */\n    public function validate()\n    {\n        foreach ($this->getAllFields() as $field) {\n            $field->validate();\n        }\n    }\n\n    /**\n     * applyModelExtensions\n     */\n    public function applyModelExtensions($model, $context = null)\n    {\n        if (!$model) {\n            throw new SystemException('Cannot extend an empty model.');\n        }\n\n        $fillable = [];\n\n        foreach ($this->getAllFields() as $field) {\n            if (in_array($context, ['export', 'import'])) {\n                $field->extendBatchModelObject($model);\n            }\n            else {\n                $field->extendModel($model);\n            }\n\n            if ($field->guarded !== true) {\n                $fillable[] = $field->fieldName;\n            }\n        }\n\n        if ($fillable) {","sourceCodeStart":55,"sourceCodeEnd":91,"githubUrl":"https://github.com/octobercms/october/blob/b608633a7e8922487d91a8161499020121c3b3bf/modules/tailor/classes/Fieldset.php#L55-L91","documentation":"Fieldset::applyModelExtensions($model, $context) walks every field and calls extendModel()/extendBatchModelObject() on it. A null or false model gives the fields nothing to extend, so the method fails fast with a SystemException rather than silently corrupting the fieldset-to-model binding.","triggerScenarios":"Calling applyModelExtensions(null), passing the result of a lookup such as Model::find($missingId) that returned null, or invoking it before the model instance was constructed.","commonSituations":"Record deleted between fetch and extension in queue jobs; optional relations yielding null; import/seed scripts that assume every iteration has a model.","solutions":["Guard the call: only invoke applyModelExtensions() on an existing model instance.","Use findOrFail() for lookups so a missing record fails at the source with a clearer error.","In loops over optional collections, skip null entries before extending."],"exampleFix":"// before\n$model = EntryRecord::find($id);\n$fieldset->applyModelExtensions($model);\n\n// after\n$model = EntryRecord::findOrFail($id);\n$fieldset->applyModelExtensions($model);","handlingStrategy":"type-guard","validationCode":"if (!$model instanceof \\October\\Rain\\Database\\Model) {\n    throw new \\RuntimeException('Cannot apply model extensions: model instance missing.');\n}","typeGuard":"function isExtensibleModel($model): bool\n{\n    return $model instanceof \\October\\Rain\\Database\\Model;\n}","tryCatchPattern":"try {\n    $fieldset->applyModelExtensions($model);\n} catch (\\SystemException $e) {\n    // model was null — re-fetch the record or skip this iteration\n}","preventionTips":["Never pass the result of Model::find() directly; use findOrFail() or an explicit null check.","In loops over optional relations, filter nulls before calling applyModelExtensions()."],"tags":["tailor","fieldset","null-model","api-misuse"],"backgroundTag":"null-argument","analyzedSha":"b608633a7e8922487d91a8161499020121c3b3bf","analyzedAt":"2026-08-21T04:24:57.515Z","schemaVersion":2},"datasetVersion":"2026-08-21T11:28:35.574Z"}