Repeating the same sort attribute with reverse direction overwrites the previous direction for that attribute
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Anfängerfreundlichkeit
- 35/100
Rechercherichtung
Beginne damit, GET /foos?sort=bar,baz,-bar zu reproduzieren, und untersuche, wie die Sortierung des Ressourcenindex an die order-Methode von ActiveRecord übergeben wird. Bestätige, dass die erste Richtung für ein wiederholtes Attribut beibehalten wird, und überprüfe anschließend das generierte ORDER BY-Verhalten anhand der im Issue beschriebenen erwarteten Priorität.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
This issue is a (choose one):
- Problem/bug report.
Checklist before submitting:
- I've searched for an existing issue.
- I've asked my question on Gitter and have not received a satisfactory answer.
- I've included a complete bug report template. This step helps us and allows us to see the bug without trying to reproduce the problem from your description. It helps you because you will frequently detect if it's a problem specific to your project.
- The feature I'm asking for is compliant with the JSON:API spec.
Description
So, this is a pretty slim edge case. It concerns repetition of an attribute in the sort param, which can yield some arguably weird results that are possibly not compliant with the JSON:API spec recommendations:
Sort fields SHOULD be applied in the order specified.
Scenario
The index of a resource is called with a sort param, where the same attribute occurs more than once with different directions:
GET /foos?sort=bar,baz,-bar
Expected outcome
The records are ordered as specified by all the sort params, with an order of precedence from left to right. Any repetitions of the same attribute can be ignored, since they won't make a difference.
ORDER BY `foos`.`bar` ASC, `foos`.`baz` ASC, `foos`.`bar` DESC
or, equivalently, ignoring the repeated attributes:
ORDER BY `foos`.`bar` ASC, `foos`.`baz` ASC
Actual outcome
Whenever a sort attribute is repeated, its direction overwrites the previous direction of that same attribute.
ORDER BY `foos`.`bar` DESC, `foos`.`baz` ASC
Since ActiveRecord's order uses keyword arguments, calling it with repeated arguments will result in the repeated value overwriting the original value (with a warning). So it could be argued that the present behavior is consistent with how ActiveRecord works.
However, considering sort order in a more general sense or in the context of an SQL query it seems reasonable to me that a repeating value should not overwrite the original value.
- Vorherrschende Sprache
- Ruby
- Sterne
- 2.3k
- Forks
- 547
- PR-Merge-Kennzahlen
- Keine gemergten PRs in 30 T.
Entwicklungsumgebung
- Kein Dockerfile und keine Docker-Compose-Datei
- Hat eine Pull-Request-Vorlage
- Kein Beitragsleitfaden
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus JSONAPI-Resources/jsonapi-resources
-
Fix incorrect translation key for parameter_not_allowed.detailEvtl. vergeben @pozzer hat das vor 594 Tagen übernommen. Offen
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 85/100
-
ArgumentError with Rails 8.1Evtl. vergeben @SAY-5 hat das vor 51 Tagen übernommen. Offen
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 50/100
JSONAPI-Resources/jsonapi-resources#1488 · 1 Kommentar ·
-
Rails 8.1: jsonapi_resources DSL fails to generate relationship routes due to Resource#initialize signature changeEvtl. wieder frei Ein Pull Request dazu wurde ohne Merge geschlossen. Offen
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 42/100
JSONAPI-Resources/jsonapi-resources#1479 · 2 Kommentare ·
-
Schwierigkeit 4/5 3-5 Tage Anfängerfreundlichkeit 30/100
JSONAPI-Resources/jsonapi-resources#1477 · 3 Kommentare · 1 Reaktion ·
-
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 45/100
Alle Issues in JSONAPI-Resources/jsonapi-resources
Ähnliche Issues
-
agent:triaged bug bughunt pm:bundler priority:p1
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
SocketDev/socket-patch#1573 · 1 Kommentar ·
Maintainer antworten meist innerhalb von 1 Tag
-
bug chat verified
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
Maintainer antworten meist innerhalb von 6 Tagen
-
🐞 bug pending triage
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
CircuitVerse/CircuitVerse#8031 · 2 Kommentare ·
Maintainer antworten meist innerhalb von 1 Tag
-
BazaRb::Fake#enter rejects dotted badges accepted by BazaRb#enterEvtl. vergeben Ein verknüpfter Pull Request ist offen oder bereits gemergt. Offen
Schwierigkeit 1/5 1-3 Stunden Anfängerfreundlichkeit 84/100
Maintainer antworten meist innerhalb von 1 Tag
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 70/100
riscv/riscv-unified-db#2740 ·
Maintainer antworten meist innerhalb von 1 Tag