Opened 3 years ago

Closed 3 years ago

Last modified 3 years ago

#29441 closed Cleanup/optimization (wontfix)

Allow dumpdata in YAML using ruamel.yaml rather than PyYaml.

Reported by: Rémy Hubscher Owned by: Daniel Rios
Component: Core (Serialization) Version: 2.0
Severity: Normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no


For some reason, ruamel.yaml is a recommanded lib for loading Yaml in Python.
However Django dumpdata command ask for PyYaml.

Could we consider having trying to use ruamel.yaml if PyYaml is not installed but ruamel.yaml is?

Change History (3)

comment:1 Changed 3 years ago by Tim Graham

Component: UncategorizedCore (Serialization)
Type: UncategorizedCleanup/optimization

Recommended by who? What are the advantages of switching? Is it backwards compatible?

comment:2 Changed 3 years ago by Daniel Rios

Owner: changed from nobody to Daniel Rios
Status: newassigned

comment:3 Changed 3 years ago by Daniel Rios

Resolution: wontfix
Status: assignedclosed

First, reasons should be provided as to why something is recommended. In this case, ruaml is recommended because it is, as far as my research has taken me, the only other python yaml library out there.

The preference for the pyyaml module is baked into django/core/serializers/ in the BUILTIN_SERIALIZERS constant at

I don't think it makes sense to have another built-in serializer. However, there is a workaround:

Django does offer the possibility to use your own serializer in the docstring of the same file (, but the actual user-facing documentation seems to be nonexistent.

I was able to, however, overwrite the preference for pyyaml by installing ruamel and with SERIALIZATION_MODULES in as follows:

    'yaml': 'ruamel.yaml.serializer'

I was unable to get it running because ruaml (even though based on pyyaml) is incompatible to the way Django handles serializers. However, the fact that Django does support other serializers means that it would be possible to get ruaml to work.

An idea would be to create a third party package django-ruaml-serializer that patches the differences in ruaml to work with the existing django serializer.

Last edited 3 years ago by Daniel Rios (previous) (diff)
Note: See TracTickets for help on using tickets.
Back to Top