Opened 9 years ago

Last modified 5 weeks ago

#11927 assigned New feature

Allow manage.py dumpdata to dump YAML in block style

Reported by: sampablokuper Owned by: Matthijs Kooijman
Component: Core (Management commands) Version: master
Severity: Normal Keywords:
Cc: sam.kuper@…, tehfink, Matthijs Kooijman Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

Using

python manage.py dumpdata --format=yaml

produces output in flow style. That's OK for automated processing, but it isn't anything like as human-readable as block style YAML. For people who, like me, need to edit the fixtures manually, it would be very useful to be able to do something like:

python manage.py dumpdata --format=yaml --flowstyle=false

Attachments (2)

flow_style.patch (642 bytes) - added by Aviral Dasgupta 8 years ago.
yaml_dump_style.diff (2.8 KB) - added by Aviral Dasgupta 8 years ago.

Download all attachments as: .zip

Change History (23)

comment:1 Changed 9 years ago by sampablokuper

Cc: sam.kuper@… added

Added to CC list.

comment:2 Changed 9 years ago by Russell Keith-Magee

Triage Stage: UnreviewedAccepted

Changed 8 years ago by Aviral Dasgupta

Attachment: flow_style.patch added

comment:3 Changed 8 years ago by Aviral Dasgupta

Has patch: set
Owner: changed from nobody to Aviral Dasgupta

comment:4 Changed 8 years ago by Aviral Dasgupta

Needs documentation: set
Needs tests: set
Patch needs improvement: set

comment:5 Changed 8 years ago by Aviral Dasgupta

milestone: 1.3
Resolution: fixed
Status: newclosed

comment:6 Changed 8 years ago by Karen Tracey

Resolution: fixed
Status: closedreopened

It's not fixed until the code is checked into SVN.

comment:7 Changed 8 years ago by Ramiro Morales

Current patch simply changes situation from hardcoded flow style output to hardcoded not flow styled output and this isn't really an overall enhancement. This should be selectable from the command line (defaulting to the current style?) as proposed by the OP. Otherwise IMHO it has little changes of being committed.

Changed 8 years ago by Aviral Dasgupta

Attachment: yaml_dump_style.diff added

comment:8 Changed 8 years ago by Aviral Dasgupta

Patch needs improvement: unset
Version: 1.1SVN

Okay, I've added a new patch. With this one, you can use --flowstyle for flow style and --blockstyle for block style YAML dumps.

comment:9 Changed 8 years ago by Łukasz Rekucki

milestone: 1.3

It still needs docs and tests. Also, it's a feature, so not going to make it for 1.3;

comment:10 Changed 8 years ago by Russell Keith-Magee

Patch needs improvement: set

I'm also not wild about the idea of having 2 options to control one flag. You can't specify both --flow and --block, so why have two options? I'd rather see just --block (enabling the new block style), or if there are likely to be more styling options, a --style=block argument.

comment:11 Changed 7 years ago by Julien Phalip

Severity: Normal
Type: New feature

comment:12 Changed 6 years ago by Aymeric Augustin

UI/UX: unset

Change UI/UX from NULL to False.

comment:13 Changed 6 years ago by Aymeric Augustin

Easy pickings: unset

Change Easy pickings from NULL to False.

comment:14 Changed 6 years ago by Aviral Dasgupta

Owner: Aviral Dasgupta deleted
Status: reopenednew

comment:15 Changed 4 years ago by blockstyle@…

--blockstyle option not found?!! I'm dumping my fixtures as yaml. The flowstyle is a pita to see.
Why isn't it available? I'm using Django 1.6

comment:16 Changed 4 years ago by Simon Charette

This ticket patch needs improvement based on @russellm comments, tests and documentation.

comment:17 Changed 3 years ago by Xiao Hanyu

Owner: set to Xiao Hanyu
Status: newassigned

comment:18 Changed 6 months ago by tehfink

Cc: tehfink added

comment:19 Changed 7 weeks ago by Matthijs Kooijman

Cc: Matthijs Kooijman added
Component: Core (Serialization)Core (Management commands)
Needs tests: unset
Owner: changed from Xiao Hanyu to Matthijs Kooijman
Patch needs improvement: unset
Triage Stage: AcceptedUnreviewed

I've taken the time time to redo this patch and address the comments on the previous patch. The patch now also adds tests and documentation.

The PyYAML docs say the following:

By default, PyYAML chooses the style of a collection depending on whether it has nested collections. If a collection has nested collections, it will be assigned the block style. Otherwise it will have the flow style.

If you want collections to be always serialized in the block style, set the parameter default_flow_style of dump() to False. For instance,

In other words, this option configures the style for collections, and there are three options: Always use the flow style, always use the block style, or the default of automatically selecting. To match that, I've added a --yaml-collection-style option that takes auto, flow or block option.

Some uncertainties / notes when reviewing the patch:

  • The option name is a lot more verbose than the --style option Russel proposed. However, since it is only relevant to the yaml formatter, I've made the option name more verbose.
  • The code in django/core/management/commands/dumpdata.py only passes the option on to the serializer when the current formatter is 'yaml'. This might be a bit hardcoded, but I didn't see an easy and elegant way to do this otherwise?
  • I've left the default at "auto" as before, but I suspect that a default of "block" might be more appropriate for loaddata. The current mixed style likely produces more user surprise that the more verbose block style would, as well as being more appropriate for version control. Would it make sense to change the default? If so, should the default of the serializer class be changed as well, or just the dumpdata command?

Given this is a new feature, I've targeted the docs at 2.2.

The patch is available on github: https://github.com/django/django/pull/10117

comment:20 Changed 7 weeks ago by Tim Graham

Needs documentation: unset
Triage Stage: UnreviewedAccepted

comment:21 Changed 5 weeks ago by Tim Graham

Patch needs improvement: set
Note: See TracTickets for help on using tickets.
Back to Top