[Django] #29441: Allow dumpdata in YAML using ruamel.yaml rather than PyYaml.

3 views
Skip to first unread message

Django

unread,
May 25, 2018, 6:13:52 AM5/25/18
to django-...@googlegroups.com
#29441: Allow dumpdata in YAML using ruamel.yaml rather than PyYaml.
-----------------------------------------+------------------------
Reporter: Rémy Hubscher | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.0
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+------------------------
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?

--
Ticket URL: <https://code.djangoproject.com/ticket/29441>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
May 25, 2018, 10:50:08 AM5/25/18
to django-...@googlegroups.com
#29441: Allow dumpdata in YAML using ruamel.yaml rather than PyYaml.
-------------------------------------+-------------------------------------

Reporter: Rémy Hubscher | Owner: nobody
Type: | Status: new
Cleanup/optimization |
Component: Core | Version: 2.0
(Serialization) |
Severity: Normal | Resolution:

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* type: Uncategorized => Cleanup/optimization
* component: Uncategorized => Core (Serialization)


Comment:

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

--
Ticket URL: <https://code.djangoproject.com/ticket/29441#comment:1>

Django

unread,
May 26, 2018, 10:29:15 AM5/26/18
to django-...@googlegroups.com
#29441: Allow dumpdata in YAML using ruamel.yaml rather than PyYaml.
-------------------------------------+-------------------------------------
Reporter: Rémy Hubscher | Owner: Daniel
Type: | Rios
Cleanup/optimization | Status: assigned

Component: Core | Version: 2.0
(Serialization) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Daniel Rios):

* owner: nobody => Daniel Rios
* status: new => assigned


--
Ticket URL: <https://code.djangoproject.com/ticket/29441#comment:2>

Django

unread,
May 27, 2018, 4:42:06 AM5/27/18
to django-...@googlegroups.com
#29441: Allow dumpdata in YAML using ruamel.yaml rather than PyYaml.
-------------------------------------+-------------------------------------
Reporter: Rémy Hubscher | Owner: Daniel
Type: | Rios
Cleanup/optimization | Status: closed

Component: Core | Version: 2.0
(Serialization) |
Severity: Normal | Resolution: wontfix

Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Daniel Rios):

* status: assigned => closed
* resolution: => wontfix


Comment:

Hi.
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/__init__.py` in the `BUILTIN_SERIALIZERS`
constant at
https://github.com/django/django/blob/5cc81cd9eb69f5f7a711412c02039b435c393135/django/core/serializers/__init__.py#L26

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
(https://github.com/django/django/blob/5cc81cd9eb69f5f7a711412c02039b435c393135/django/core/serializers/__init__.py#L10),
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 settings.py as follows:
{{{
SERIALIZATION_MODULES = {
'yaml': 'ruamel.yaml.serializer'
}
}}}

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

A better 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.

--
Ticket URL: <https://code.djangoproject.com/ticket/29441#comment:3>

Reply all
Reply to author
Forward
0 new messages