Skip to content

Fix #1854: Preserve @querystring order by making sort_keys optional#1985

Open
hasansyed107 wants to merge 9 commits intoplone:mainfrom
hasansyed107:fix-sort-keys-ordering-1854
Open

Fix #1854: Preserve @querystring order by making sort_keys optional#1985
hasansyed107 wants to merge 9 commits intoplone:mainfrom
hasansyed107:fix-sort-keys-ordering-1854

Conversation

@hasansyed107
Copy link

@hasansyed107 hasansyed107 commented Feb 16, 2026

  • I signed and returned the Plone Contributor Agreement, and received and accepted an invitation to join a team in the Plone GitHub organization.
  • I verified there aren't any other open pull requests for the same change.
  • I followed the guidelines in Contributing to Plone.
  • I successfully ran code quality checks on my changes locally.
  • I successfully ran tests on my changes locally.
  • If needed, I added new tests for my changes.
  • If needed, I added documentation for my changes.
  • I included a change log entry in my commits.

If your pull request closes an open issue, include the exact text below, immediately followed by the issue number. When your pull request gets merged, then that issue will close automatically.

Closes #


📚 Documentation preview 📚: https://plonerestapi--1985.org.readthedocs.build/

@mister-roboto
Copy link

Syed Ahmed mubasiruddin the email address in your commit does not match an email in your GitHub account. Thus it is impossible to determine whether you have signed the Plone Contributor Agreement, which is required to merge this pull request.

Learn about the Plone Contributor Agreement: https://plone.org/foundation/contributors-agreement

If you have sent in your Plone Contributor Agreement, and received and accepted an invitation to join the Plone GitHub organization, then you might need to either add the email address on your Agreement to your GitHub account or change the email address in your commits. If you need to do the latter, then you should squash the commits with your matching email and push them.

Add more emails to your GitHub account:
https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-email-preferences/adding-an-email-address-to-your-github-account

Change the email address in your commits:
https://docs.github.com/en/account-and-profile/setting-up-and-managing-your-personal-account-on-github/managing-email-preferences/setting-your-commit-email-address

@mister-roboto
Copy link

@hasansyed107 thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically.

Happy hacking!

@hasansyed107 hasansyed107 force-pushed the fix-sort-keys-ordering-1854 branch from 8248303 to febe325 Compare February 16, 2026 16:33
@mister-roboto
Copy link

@hasansyed107 you need to sign the Plone Contributor Agreement to merge this pull request.

Learn about the Plone Contributor Agreement: https://plone.org/foundation/contributors-agreement

If you have already signed the agreement, please allow a week for your agreement to be processed.
Once it is processed, you will receive an email invitation to join the plone GitHub organization as a Contributor.

If after a week you have not received an invitation, then please contact agreements@plone.org.

news/1854.bugfix Outdated
@@ -0,0 +1 @@
Allow services to opt-out of JSON sort_keys to preserve @querystring order.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add markup and give yourself credit.

Suggested change
Allow services to opt-out of JSON sort_keys to preserve @querystring order.
Allow services to opt-out of JSON `sort_keys` to preserve `@querystring` order. @hasansyed107

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still hasn't been updated. Don't know why it was resolved.

@jensens jensens marked this pull request as draft February 16, 2026 20:41
@jensens
Copy link
Member

jensens commented Feb 16, 2026

needs some love and a description.

@mister-roboto
Copy link

@hasansyed107 you need to sign the Plone Contributor Agreement to merge this pull request.

Learn about the Plone Contributor Agreement: https://plone.org/foundation/contributors-agreement

If you have already signed the agreement, please allow a week for your agreement to be processed.
Once it is processed, you will receive an email invitation to join the plone GitHub organization as a Contributor.

If after a week you have not received an invitation, then please contact agreements@plone.org.

Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not a good solution to the problem.

JSON does not guarantee that the order of object properties will be preserved.

When the order is important, we should serialize a list instead.

This means we have to first update Volto to accept either the existing object or a list. Then we can update the format in plone.restapi and make a breaking release.

@hasansyed107 hasansyed107 force-pushed the fix-sort-keys-ordering-1854 branch from 3195b28 to dfaf1c1 Compare February 17, 2026 11:09
@mister-roboto
Copy link

@hasansyed107 you need to sign the Plone Contributor Agreement to merge this pull request.

Learn about the Plone Contributor Agreement: https://plone.org/foundation/contributors-agreement

If you have already signed the agreement, please allow a week for your agreement to be processed.
Once it is processed, you will receive an email invitation to join the plone GitHub organization as a Contributor.

If after a week you have not received an invitation, then please contact agreements@plone.org.

@hasansyed107 hasansyed107 marked this pull request as ready for review February 17, 2026 11:20
@hasansyed107 hasansyed107 marked this pull request as draft February 17, 2026 11:20
@hasansyed107
Copy link
Author

Thank you for the clarification, @davisagli. I agree that a list-based structure is the correct approach when order must be preserved.

To confirm the expected structure: should the current mapping be converted into a list of objects with the key represented as an id property?

I’ll start reviewing the relevant Volto components to plan backward compatibility.

@hasansyed107
Copy link
Author

Hi @davisagli and @jensens, I have updated the @querystring service to return ordered lists for indexes and sortable_indexes as requested.

To ensure backward compatibility, I have opened the companion Volto PR here: https://github.com/plone/volto/pull/7917

@jenkins-plone-org please run jobs

@hasansyed107 hasansyed107 marked this pull request as ready for review February 17, 2026 17:04
news/1854.bugfix Outdated
@@ -0,0 +1 @@
Allow services to opt-out of JSON sort_keys to preserve @querystring order.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still hasn't been updated. Don't know why it was resolved.

Copy link
Member

@davisagli davisagli left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are tests which are failing because of the change and need to be updated. And a few other details.

sort_keys = getattr(self, "sort_keys", True)
return json.dumps(
content, indent=2, sort_keys=True, separators=(", ", ": ")
content, indent=2, sort_keys=sort_keys, separators=(", ", ": ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer necessary

@hasansyed107
Copy link
Author

Hi @davisagli and @stevepiercy,

I have completed the requested updates for this PR. It is now aligned with the corresponding frontend changes in Volto.

Summary of updates:

Implementation: Restored the original Service class docstrings and ensured the sort_keys opt-out logic is clean and non-breaking.

Documentation: Updated the OpenAPI specification by running make docs to reflect the change to a list-based structure in the @querystring endpoint.

News Fragment: Added a proper news fragment (news/1854.feature) with the correct credits and description.

Tests: Updated the Python backend tests to match the new response format.

Linked Volto PR: plone/volto#7917

@jenkins-plone-org please run jobs

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove this file. It shouldn't be committed.

@@ -0,0 +1 @@
Allow services to opt-out of JSON sort_keys to preserve @querystring order. @hasansyed107
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still hasn't been resolved correctly with MyST markup.

Suggested change
Allow services to opt-out of JSON sort_keys to preserve @querystring order. @hasansyed107
Allow services to opt-out of JSON `sort_keys` to preserve `@querystring` order. @hasansyed107

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More importantly, this only describes the part of the pull request that is no longer relevant.

Suggested change
Allow services to opt-out of JSON sort_keys to preserve @querystring order. @hasansyed107
The `@querystring` service now returns index as a list rather than an object, to preserve the order. @hasansyed107

And, it's a breaking change, so the file extension needs to be .breaking instead of .feature

@@ -0,0 +1 @@
Allow services to opt-out of JSON sort_keys to preserve @querystring order. @hasansyed107
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

More importantly, this only describes the part of the pull request that is no longer relevant.

Suggested change
Allow services to opt-out of JSON sort_keys to preserve @querystring order. @hasansyed107
The `@querystring` service now returns index as a list rather than an object, to preserve the order. @hasansyed107

And, it's a breaking change, so the file extension needs to be .breaking instead of .feature

sort_keys = getattr(self, "sort_keys", True)
return json.dumps(
content, indent=2, sort_keys=True, separators=(", ", ": ")
content, indent=2, sort_keys=sort_keys, separators=(", ", ": ")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is no longer relevant since we switched to returning a list. Please remove it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants

Comments