Description
On Craft CMS 5.10.13.1 with MySQL 8.0, opening a Control Panel entry editor can fail with:
SQLSTATE[42000]: Syntax error or access violation: 1582 Incorrect parameter count in the call to native function 'FIELD'
The generated SQL contains:
ORDER BY FIELD(`elements`.`id`)
Suspected cause
craft\\fields\\Assets::normalizeValue() calls fixedOrder() after filtering the submitted asset IDs, without checking whether the resulting array is empty:
$query
->id(array_values(array_filter($value)))
->fixedOrder();
Craft’s MySQL query builder then generates FIELD(column) with no values. BaseRelationField::normalizeValue() already guards its equivalent FixedOrderExpression call with if (!empty($value)), which suggests the Assets-specific path may be missing the same guard.
Environment
- Craft CMS: 5.10.13.1
- Yii: 2.0.55
- MySQL: 8.0.x
- PHP: 8.4.x
Expected behaviour
An empty asset relation should produce an empty result or skip fixed ordering, without generating invalid SQL.
Actual behaviour
The request fails with MySQL error 1582 because FIELD() is called with only its column argument.
Additional context
The error was observed while opening an existing entry in the Control Panel, not while saving content. A temporary application-level query-builder override avoids the exception, but a guard in the relation-field normalisation path would be safer and more targeted.
Description
On Craft CMS 5.10.13.1 with MySQL 8.0, opening a Control Panel entry editor can fail with:
The generated SQL contains:
Suspected cause
craft\\fields\\Assets::normalizeValue()callsfixedOrder()after filtering the submitted asset IDs, without checking whether the resulting array is empty:Craft’s MySQL query builder then generates
FIELD(column)with no values.BaseRelationField::normalizeValue()already guards its equivalentFixedOrderExpressioncall withif (!empty($value)), which suggests the Assets-specific path may be missing the same guard.Environment
Expected behaviour
An empty asset relation should produce an empty result or skip fixed ordering, without generating invalid SQL.
Actual behaviour
The request fails with MySQL error 1582 because
FIELD()is called with only its column argument.Additional context
The error was observed while opening an existing entry in the Control Panel, not while saving content. A temporary application-level query-builder override avoids the exception, but a guard in the relation-field normalisation path would be safer and more targeted.