Yaml serializer output

76 views
Skip to first unread message

Sergey Fursov

unread,
Dec 26, 2021, 2:21:42 PM12/26/21
to Django developers (Contributions to Django itself)
Hi there,

Before opening a ticket I would like to discuss my problem here.

Django docs say:

```
YAML

YAML serialization looks quite similar to JSON. The object list is serialized as a sequence mappings with the keys “pk”, “model” and “fields”. Each field is again a mapping with the key being name of the field and the value the value:

- fields: {expire_date: !!timestamp '2013-01-16 08:16:59.844560+00:00'} model: sessions.session pk: 4b678b301dfd8a4e0dad910de3ae245b
```

But I cannot find a way to produce the same output. Both available to me environments (MacOS and Debian linux inside a Docker container) product a simpler output, like

```
>> obj = core.ModelA.objects.get(id=1)
>> print(serializers.serialize('yaml', [obj]))
- model: core.modela
  pk: 1
  fields:
    created: 2017-02-05 16:11:44.310613+00:00
    .... other fields ...
```

I've found this after running full Django test suite when 6 test from django/tests/timezones/tests.py failed. Example failure:

```
FAIL: test_naive_datetime_with_microsecond (timezones.tests.SerializationTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/geyser/coding/opensource/django/tests/timezones/tests.py", line 671, in test_naive_datetime_with_microsecond
    self.assert_yaml_contains_datetime(data, "2011-09-01 13:20:30.405060")
  File "/Users/geyser/coding/opensource/django/tests/timezones/tests.py", line 625, in assert_yaml_contains_datetime
    self.assertRegex(yaml, r"\n  fields: {dt: !(!timestamp)? '%s'}" % re.escape(dt))
AssertionError: Regex didn't match: "\\n  fields: {dt: !(!timestamp)? '2011\\-09\\-01\\ 13:20:30\\.405060'}" not found in '- model: timezones.event\n  pk: null\n  fields:\n    dt: 2011-09-01 13:20:30.405060\n'
```

I've tried to install several different pyyaml versions (from 6.0 down to 5.1.2).

Do I miss something or it is a valid issue for opening a ticket?

Thanks,
Sergey Fursov

Sergey Fursov

unread,
Dec 27, 2021, 3:13:48 AM12/27/21
to Django developers (Contributions to Django itself)
Please, disregard the part about failing tests, I had an old version locally without this commit applied https://github.com/django/django/commit/a57c783dd4e6dc73847081221827a1902eede88b
Anyway, I think it might be confusing (at least it is confusing to me) that by default yaml serializer produces a different output than provided in docs

воскресенье, 26 декабря 2021 г. в 22:21:42 UTC+3, Sergey Fursov:

Adam Johnson

unread,
Dec 28, 2021, 6:13:33 AM12/28/21
to Django developers (Contributions to Django itself)
I've made a PR to update the docs: https://github.com/django/django/pull/15250

--
You received this message because you are subscribed to the Google Groups "Django developers (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-develop...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/6793d234-92f5-46fa-bc19-3996626dc456n%40googlegroups.com.

Sergey Fursov

unread,
Dec 29, 2021, 2:01:17 PM12/29/21
to django-d...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages