Skip to content

fix: MultipleChoiceField use ordered sort #9735

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

fbozhang
Copy link

@fbozhang fbozhang commented Jul 5, 2025

This modification has the following advantages:

  1. Maintain the input order.
  2. Prevent the output from being a set, which would cause issues with JSON serialization (e.g., when passing parameters to certain third-party SDKs that may internally use json.dumps, and I cannot modify the third party's encoder).

Copy link
Member

@auvipy auvipy left a comment

Choose a reason for hiding this comment

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

please also add unit tests to verify this and make the CI green

@fbozhang
Copy link
Author

fbozhang commented Jul 5, 2025

please also add unit tests to verify this and make the CI green

I’ve added the tests and the CI is green now.

Copy link
Member

@browniebroke browniebroke left a comment

Choose a reason for hiding this comment

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

Seems sensible to me 👍🏻

However, it will have to wait for 3.17 as I see this as potentially disruptive for some downstream users. Left a small suggestion

@@ -199,14 +199,14 @@ def test_nested_serializer_with_list_json(self):
serializer = self.Serializer(data=input_data)

assert serializer.is_valid()
assert serializer.validated_data['nested']['example'] == {1, 2}
assert serializer.validated_data['nested']['example'] == [1, 2]
Copy link
Member

Choose a reason for hiding this comment

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

Hum, that's a bit unfortunate that this data type is exposed at this level. I'm thinking of potential users testing at the serializer level might get some new test failures with this change.

@browniebroke browniebroke added this to the 3.17 milestone Jul 6, 2025
@fbozhang
Copy link
Author

fbozhang commented Jul 6, 2025

Seems sensible to me 👍🏻

However, it will have to wait for 3.17 as I see this as potentially disruptive for some downstream users. Left a small suggestion

Good point — waiting for 3.17 sounds like the right call. Appreciate the suggestion!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants