phalcon/cphalcon · error · Phalcon\Mvc\Model\MetaData\Exceptions\CorruptedMetaData
The meta-data is invalid or is corrupt
Error message
The meta-data is invalid or is corrupt
What it means
MetaData::getAttributes(model) returns the full list of mapped attribute (column) names for a model, reading slot MODELS_ATTRIBUTES from the model's metadata record. The slot must be an array; if the stored value is any other type (string, int, null), Phalcon treats the record as damaged and throws CorruptedMetaData rather than return a value that would produce broken SQL. The record is populated from the cache adapter, the model's metaData() method, or the metadata strategy on first miss.
Source
Thrown at phalcon/Mvc/Model/MetaData.zep:210
/**
* Returns table attributes names (fields)
*
*```php
* print_r(
* $metaData->getAttributes(
* new Invoices()
* )
* );
*```
*/
public function getAttributes(<ModelInterface> model) -> array
{
var data;
let data = this->readMetaDataIndex(model, self::MODELS_ATTRIBUTES);
if unlikely typeof data != "array" {
throw new CorruptedMetaData();
}
return data;
}
/**
* Returns attributes that must be ignored from the INSERT SQL generation
*
*```php
* print_r(
* $metaData->getAutomaticCreateAttributes(
* new Invoices()
* )
* );
*```
*/
public function getAutomaticCreateAttributes(<ModelInterface> model) -> array
{View on GitHub (pinned to b7419de9cd)
Solutions
- Flush the metadata storage and let Phalcon regenerate it: $metaData->reset() plus deleting the 'meta-*' entries (or the adapter directory/keys).
- Fix any custom metaData() method so MODELS_ATTRIBUTES maps to an array of column names.
- After Phalcon upgrades, change the metadata adapter prefix or key so old and new entries cannot mix, and use the same serializer on every server.
- Never call writeMetaDataIndex() with non-array payloads for the MODEL_* constants.
Example fix
// before
public function metaData(): array
{
return [
MetaData::MODELS_ATTRIBUTES => 'inv_id,inv_cst_id', // string corrupts the slot
];
}
// after
public function metaData(): array
{
return [
MetaData::MODELS_ATTRIBUTES => ['inv_id', 'inv_cst_id'], // array of column names
];
} Defensive patterns
Strategy: retry
Validate before calling
use Phalcon\Mvc\Model\MetaData;
$data = $metaData->readMetaData($model);
if (null !== $data && !is_array($data[MetaData::MODELS_ATTRIBUTES] ?? null)) {
$metaData->reset(); // drop the in-memory copy
clearMetadataBackend($metaData); // adapter-specific: delete 'meta-*' entries
} Type guard
function metadataSlotIsArray(?array $record, int $index): bool
{
return null === $record || is_array($record[$index] ?? null);
} Try / catch
use Phalcon\Mvc\Model\MetaData\Exceptions\CorruptedMetaData;
try {
$attributes = $metaData->getAttributes($model);
} catch (CorruptedMetaData $e) {
$metaData->reset();
clearMetadataBackend($metaData); // adapter-specific flush
$attributes = $metaData->getAttributes($model); // regenerate exactly once
} Prevention
- Flush the metadata cache on every deploy that changes the schema or the Phalcon version.
- Pin one serializer for the metadata adapter on all nodes sharing the backend.
- Ship a boot smoke test calling getAttributes() on one representative model per database.
When it happens
Trigger: Calling getAttributes($model) (directly, or indirectly through model assign/save/query building) after the cached 'meta-*' entry for the model holds a non-array in its MODELS_ATTRIBUTES slot, or after a custom metaData() method / writeMetaDataIndex() call stored a non-array there.
Common situations: Metadata cache (Redis, Libmemcached, APCu, Stream files) still holding entries written by an older Phalcon version with a different structure; deploying schema changes without flushing metadata; a custom metaData() method mapping MODELS_ATTRIBUTES to a comma-separated string; serializer mismatch (igbinary vs serialize) between servers sharing the backend.
Related errors
- No annotations were found in class {className}
- Identity column '{identityField}' isn't part of the table co
- Column '{column}' have not defined a data type in '{classNam
- Column '{column}' isn't part of the table columns in '{class
- A dependency injection container is required to access inter
AI-assisted analysis of phalcon/cphalcon@b7419de9cd (2026-08-21).
Data as JSON: /api/errors/7f4f48ce24e7205c.
Report an issue: GitHub.