Django

Code

Ticket #5268 (closed: fixed)

Opened 10 months ago

Last modified 7 months ago

Remove Python specific types from YAML output (use safe_dump?)

Reported by: django@poelzi.org Assigned to: poelzi
Milestone: Component: Serialization
Version: SVN Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

dumps produced by yaml.dump are not very language neutral. safe_dump=True as serialize parameter will call yaml.safe_dump which doesn't have this problem.

Attachments

patch_yaml_safe_dumper.txt (1.6 kB) - added by django@poelzi.org on 08/26/07 19:15:03.
add safe_dump argument to yaml serializer
yaml_patch.diff (1.6 kB) - added by poelzi on 11/30/07 19:49:57.
better patch. use safe_dump with tests

Change History

08/26/07 19:15:03 changed by django@poelzi.org

  • attachment patch_yaml_safe_dumper.txt added.

add safe_dump argument to yaml serializer

08/26/07 19:40:17 changed by russellm

  • needs_better_patch changed.
  • needs_tests changed.
  • needs_docs changed.

Configurability is great, but is there any compelling reason that we shouldn't just change the implementation to use safe_dump all the time? I'm not a YAML expert, but looking at the PyYAML docs, it appears that the only place the difference would matter is when serializing 'arbitrary Python objects'. I don't think we need this capability, and if we are, we should be able to work around it without too much difficulty.

08/26/07 20:50:18 changed by django@poelzi.org

a unicode object for example is considered a 'arbitrary Python objects'. this creates such nice looking dumps like:

https://db.leipzig.freifunk.net/dns/yaml/domain/list/

the !!python/unicode is not very portable. however, i asked the yaml programmer about this issue befor filling this bug and he said suggested using safe_dump. i'm not so sure about this, using dump has many advantages when it comes to terms of mapping verify presice things. I'm thinking about writing a extended mapper that causes relations to be mapped like the model. But for portability reasons this is not suggested, therefor I suggest this argument.

08/27/07 09:43:08 changed by anonymous

  • stage changed from Unreviewed to Design decision needed.

09/07/07 23:55:26 changed by russellm

  • needs_better_patch set to 1.
  • summary changed from add yaml save_dump argument to Remove Python specific types from YAML output (use safe_dump?).
  • needs_tests set to 1.
  • stage changed from Design decision needed to Accepted.

Ok. I'm -1 to adding a safe_dump argument to the serializer. However, I agree that the output format is not pretty. I've changed the ticket title to reflect the underlying problem.

It looks as if the YAML output has changed significantly since the unicode branch was merged - this is the underlying problem that should be solved. The solution may be to switch to using safe_dump all the time - I'll leave that decision to whoever tackles this problem.

11/30/07 19:49:57 changed by poelzi

  • attachment yaml_patch.diff added.

better patch. use safe_dump with tests

11/30/07 19:50:37 changed by poelzi

  • owner changed from nobody to poelzi.
  • needs_better_patch deleted.
  • status changed from new to assigned.
  • needs_tests deleted.
  • stage changed from Accepted to Ready for checkin.

12/04/07 14:31:35 changed by jacob

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [6891]) Fixed #5268: the YAML serializer now uses yaml.safe_dump() instead the plain yaml.dump(); this makes YAML dumps more portable, and also removes the crufty '!!python/unicode' business. Thanks, poelzi.


Add/Change #5268 (Remove Python specific types from YAML output (use safe_dump?))




Change Properties
Action