octobercms/october · error · SystemException

Cannot extend an empty model.

Error message

Cannot extend an empty model.

What it means

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.

Source

Thrown at modules/tailor/classes/Fieldset.php:73

    }

    /**
     * validate all the fields
     */
    public function validate()
    {
        foreach ($this->getAllFields() as $field) {
            $field->validate();
        }
    }

    /**
     * applyModelExtensions
     */
    public function applyModelExtensions($model, $context = null)
    {
        if (!$model) {
            throw new SystemException('Cannot extend an empty model.');
        }

        $fillable = [];

        foreach ($this->getAllFields() as $field) {
            if (in_array($context, ['export', 'import'])) {
                $field->extendBatchModelObject($model);
            }
            else {
                $field->extendModel($model);
            }

            if ($field->guarded !== true) {
                $fillable[] = $field->fieldName;
            }
        }

        if ($fillable) {

View on GitHub (pinned to b608633a7e)

Solutions

  1. Guard the call: only invoke applyModelExtensions() on an existing model instance.
  2. Use findOrFail() for lookups so a missing record fails at the source with a clearer error.
  3. In loops over optional collections, skip null entries before extending.

Example fix

// before
$model = EntryRecord::find($id);
$fieldset->applyModelExtensions($model);

// after
$model = EntryRecord::findOrFail($id);
$fieldset->applyModelExtensions($model);
Defensive patterns

Strategy: type-guard

Validate before calling

if (!$model instanceof \October\Rain\Database\Model) {
    throw new \RuntimeException('Cannot apply model extensions: model instance missing.');
}

Type guard

function isExtensibleModel($model): bool
{
    return $model instanceof \October\Rain\Database\Model;
}

Try / catch

try {
    $fieldset->applyModelExtensions($model);
} catch (\SystemException $e) {
    // model was null — re-fetch the record or skip this iteration
}

Prevention

When it happens

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

Common situations: Record deleted between fetch and extension in queue jobs; optional relations yielding null; import/seed scripts that assume every iteration has a model.

Related errors


AI-assisted analysis of octobercms/october@b608633a7e (2026-08-21). Data as JSON: /api/errors/36300caf99fc1a37. Report an issue: GitHub.