Opened 46 minutes ago

Last modified 20 minutes ago

#37405 assigned Bug

Using sort_keys kwarg no longer possible with YAML serializer

Reported by: Jacob Walls Owned by: Jacob Walls
Component: Core (Serialization) Version: 6.1
Severity: Release blocker Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: yes UI/UX: no

Description

The YAML serializer takes a sort_keys option, but since we neglected to use setdefault when "defaulting" this argument in 7142667340f78403cbbcaa8f33703c494282b7b7, any existing uses could raise TypeError:

Test case for YamlSerializerTestCase:

    def test_explicit_sort_keys(self):
        serial_str = serializers.serialize(
            "yaml", Author.objects.all(), sort_keys=False
        )
        self.assertTrue(self._validate_output(serial_str))
  File "/Users/jwalls/django/tests/serializers/test_yaml.py", line 159, in test_explicit_sort_keys
    serial_str = serializers.serialize("yaml", Author.objects.all(), sort_keys=False)
    ^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/django/core/serializers/__init__.py", line 134, in serialize
    s.serialize(queryset, **options)
      ^^^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/django/core/serializers/base.py", line 149, in serialize
    self.end_serialization()
    ^^^^^^^^^^^^^^^
  File "/Users/jwalls/django/django/core/serializers/pyyaml.py", line 49, in end_serialization
    yaml.dump(
TypeError: yaml.dump() got multiple values for keyword argument 'sort_keys'

Change History (2)

comment:1 by Jacob Walls, 40 minutes ago

Has patch: set

comment:2 by Tim Graham, 20 minutes ago

Triage Stage: Unreviewed → Accepted
Note: See TracTickets for help on using tickets.
Back to Top