Opened 4 years ago

Closed 4 years ago

Last modified 3 years ago

#19115 closed Cleanup/optimization (fixed)

dumpdata should take option to output to named file

Reported by: murftone@… Owned by: nobody
Component: Documentation Version: master
Severity: Normal Keywords: dumpdata management command
Cc: d1fffuz0r@… Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: yes
Easy pickings: no UI/UX: no

Description

If the dumpdata management command could output to a named file, it would make it a lot easier to invoke dumpdata from other management commands via call_command.

Attachments (4)

19115.patch (3.8 KB) - added by Roman Gladkov 4 years ago.
19115.2.patch (684 bytes) - added by Roman Gladkov 4 years ago.
19115.3.patch (1.0 KB) - added by Roman Gladkov 4 years ago.
19115.4.patch (680 bytes) - added by Claude Paroz 4 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 4 years ago by Simon Charette

Needs documentation: unset
Needs tests: unset
Patch needs improvement: unset

We could document you can achieve this by passing a file like object as the stdout kwarg of call_command.

with open('/tmp/call_command_output') as f:
    call_command('dumpdata', stdout=f)

This looks quite easy to me.

comment:2 Changed 4 years ago by Claude Paroz

Component: Core (Management commands)Documentation
Triage Stage: UnreviewedAccepted
Type: New featureCleanup/optimization

Changed 4 years ago by Roman Gladkov

Attachment: 19115.patch added

comment:3 Changed 4 years ago by Roman Gladkov

Cc: d1fffuz0r@… added
Has patch: set
Version: 1.4master

added new optional parameter to dumpdata command, for save data to file

comment:4 Changed 4 years ago by Claude Paroz

Patch needs improvement: set

This ticket was accepted on the base that we should document the stdout usage of call_command, which is also useful for all other commands. Not to add another option to dumpdata.

Changed 4 years ago by Roman Gladkov

Attachment: 19115.2.patch added

comment:5 Changed 4 years ago by Roman Gladkov

Ok. I'm sorry, I fixed this patch and added only documentation.

comment:6 Changed 4 years ago by Claude Paroz

Thanks for your efforts. As the stdout option is valid for all commands, I'd rather add a paragraph (Output redirection) in the section https://docs.djangoproject.com/en/dev/ref/django-admin/#running-management-commands-from-your-code

Then you can just add a reference to it from the dumpdata section.

comment:7 Changed 4 years ago by Roman Gladkov

I agree. That looks better.

Changed 4 years ago by Roman Gladkov

Attachment: 19115.3.patch added

Changed 4 years ago by Claude Paroz

Attachment: 19115.4.patch added

comment:8 Changed 4 years ago by Claude Paroz

After some thoughts, here's how I'd like to document it. I don't think it's worth adding the note to the dumpdata command section, as we should then specify it also for all other commands which output data. We can count on people trying to output data with a management command to look after the call_command section.

comment:9 Changed 4 years ago by Claude Paroz <claude@…>

Resolution: fixed
Status: newclosed

In b1ac329ba9bbcba90d8ced7e16909ed169b1d16e:

Fixed #19115 -- Documented stdout/stderr options for call_command

Thanks d1ffuz0r for helping with the patch.

comment:10 Changed 4 years ago by Claude Paroz <claude@…>

In b8726179249ede88c988c13fd4b1077e49e8b151:

[1.5.x] Fixed #19115 -- Documented stdout/stderr options for call_command

Thanks d1ffuz0r for helping with the patch.
Backport of b1ac329ba from master.

comment:11 Changed 3 years ago by maa@…

how do we use this ?
./manage dumpdata --stdout=file.json ?

comment:12 in reply to:  11 Changed 3 years ago by Baptiste Mispelon

Replying to maa@…:

how do we use this ?
./manage dumpdata --stdout=file.json ?

This ticket tracker is not the best place to ask questions like this. You should use our support channels instead [1].

As for your question, since the command outputs its result, you can use your shell's output redirection feature:

./manage dumpdata > the_name_of_the_file.json

[1] https://code.djangoproject.com/wiki/TicketClosingReasons/UseSupportChannels

Note: See TracTickets for help on using tickets.
Back to Top