Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

`OrderExtension` and `OrderFilter` pass string sort directions, deprecated since `doctrine/orm` 3.7

Aperta Adatta ai principianti
#8,648 1 commento 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

@VincentLanglet ci sta già lavorando.

Dal 7/10/2026.

  • #8654 di @VincentLanglet — aperta

Valutazione

Difficoltà
2/5
Tempo stimato
1-3 ore
Idoneità per principianti
78/100
Tipo di issue
Refactoring
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
php
Ambito
backend

Direzione di ricerca

Inizia dalle righe 72 e 85 di src/Doctrine/Orm/Extension/OrderExtension.php e dalle righe 281 e 284 di src/Doctrine/Orm/Filter/OrderFilter.php, dove i letterali 'ASC'/'DESC' vengono passati a orderBy()/addOrderBy(). Introduci un piccolo helper che li mappi a \SortDirection::Ascending/Descending solo se doctrine/orm >= 3.7 (tramite Composer\InstalledVersions o riflessione su QueryBuilder::addOrderBy()), restituendo altrimenti la stringa, poi applicalo a tutti e quattro i punti di chiamata, incluso il gestimento dei nulls di OrderFilter. Completato significa nessuna deprecation di ordinamento per stringa su una richiesta di collection con doctrine/orm 3.7 e nessun rompimento su ORM 2.17/^3.3 — verifica con le suite di test esistenti di extension/filter di Doctrine ORM.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
PHP
Stelle
2.6k
Fork
987
Merge medio
1g 8h
PR unite (30g)
90

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di api-platform/core

Tutte le issue di api-platform/core

Issue simili

Altre issue su PHP

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.