diff options
| author | Simon Charette <charette.s@gmail.com> | 2015-04-01 15:42:09 -0400 |
|---|---|---|
| committer | Simon Charette <charette.s@gmail.com> | 2015-04-02 15:21:43 -0400 |
| commit | 5bc3123479bd97dc9d8a36fa9a3421a71063d1da (patch) | |
| tree | efe8d154cb1487c318b436f6f5813863e6b042b4 /django/core/serializers/pyyaml.py | |
| parent | 147ac856131233b2960503c3cc0d65059a57851a (diff) | |
Fixed #24558 -- Made dumpdata mapping ordering deterministic.
Thanks to gfairchild for the report and Claude for the review.
Diffstat (limited to 'django/core/serializers/pyyaml.py')
| -rw-r--r-- | django/core/serializers/pyyaml.py | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/django/core/serializers/pyyaml.py b/django/core/serializers/pyyaml.py index 105072b54e..04adc8129a 100644 --- a/django/core/serializers/pyyaml.py +++ b/django/core/serializers/pyyaml.py @@ -4,6 +4,7 @@ YAML serializer. Requires PyYaml (http://pyyaml.org/), but that's checked for in __init__. """ +import collections import decimal import sys from io import StringIO @@ -29,7 +30,11 @@ class DjangoSafeDumper(SafeDumper): def represent_decimal(self, data): return self.represent_scalar('tag:yaml.org,2002:str', str(data)) + def represent_ordered_dict(self, data): + return self.represent_mapping('tag:yaml.org,2002:map', data.items()) + DjangoSafeDumper.add_representer(decimal.Decimal, DjangoSafeDumper.represent_decimal) +DjangoSafeDumper.add_representer(collections.OrderedDict, DjangoSafeDumper.represent_ordered_dict) class Serializer(PythonSerializer): |
