You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
OrderExtension and OrderFilter pass string sort directions, deprecated since doctrine/orm 3.7 #8648
API Platform affected: 4.3.21, and the current heads of 4.4, 5.0 and main
The doctrine/orm 3.7 deprecates string based sort directions in QueryBuilder::orderBy() and addOrderBy(). It wants the PHP 8.6 \SortDirection enum instead, which ORM itself requires through symfony/polyfill-php86. See "Deprecated using strings or null as sort directions" in https://github.com/doctrine/orm/blob/3.7.x/UPGRADE.md
OrderExtension and OrderFilter still pass 'ASC' and 'DESC' literals:
Line 85 matters most. collection.order defaults to ASC, so every Doctrine collection without its own order gets addOrderBy('o.id', 'ASC'). Any app on doctrine/orm 3.7 sees this on its first collection request:
Passing string as $order to Doctrine\ORM\QueryBuilder::addOrderBy() is deprecated, use an instance of SortDirection instead.
(QueryBuilder.php:1518 called by QueryBuilder.php:1254, https://github.com/doctrine/orm/issues/11313, package doctrine/orm)
The message names QueryBuilder.php as the caller, and doctrine/deprecations reports it only once per process, so it took me a while to trace it back to API Platform. We fixed all our own orderBy() calls and it kept coming.
How to reproduce
PHP 8.4, Symfony 8.1, doctrine/orm 3.7.3, deprecations visible (for example PHPUnit with failOnDeprecation). Request any Doctrine-backed GetCollection.
Possible solution
As the API Platform still allows doctrine/orm ^2.17 || ^3.3, passing the enum unconditionally would break older ORM versions. A small helper could map 'ASC'/'DESC' to \SortDirection::Ascending/Descending when the installed ORM is 3.7 or newer, and return the string otherwise. The version check could use i.e. Composer\InstalledVersions, or reflection on the second parameter of QueryBuilder::addOrderBy(). OrderFilter needs the same mapping, including the nulls handling on line 281.
I could prepare such PR if proposed solution fits. Which branch should it target then, 4.4?
Fixed by #8654 on 5.0, released in v5.0.3 (and #8662 for SortDirection values in order). 4.4 keeps the string directions since the BC helper only lives on 5.0.
Activity
VincentLanglet commentedon Oct 7, 2026
Thanks, I opened #8654
soyuka commentedon Oct 13, 2026
Fixed by #8654 on 5.0, released in v5.0.3 (and #8662 for
SortDirectionvalues inorder). 4.4 keeps the string directions since the BC helper only lives on 5.0.