Opened 3 years ago

Closed 3 years ago

Last modified 19 months 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 d1ffuz0r 3 years ago.
19115.2.patch (684 bytes) - added by d1ffuz0r 3 years ago.
19115.3.patch (1.0 KB) - added by d1ffuz0r 3 years ago.
19115.4.patch (680 bytes) - added by claudep 3 years ago.

Download all attachments as: .zip

Change History (16)

comment:1 Changed 3 years ago by charettes

  • 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 3 years ago by claudep

  • Component changed from Core (Management commands) to Documentation
  • Triage Stage changed from Unreviewed to Accepted
  • Type changed from New feature to Cleanup/optimization

Changed 3 years ago by d1ffuz0r

comment:3 Changed 3 years ago by d1ffuz0r

  • Cc d1fffuz0r@… added
  • Has patch set
  • Version changed from 1.4 to master

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

comment:4 Changed 3 years ago by claudep

  • 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 3 years ago by d1ffuz0r

comment:5 Changed 3 years ago by d1ffuz0r

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

comment:6 Changed 3 years ago by claudep

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 3 years ago by d1ffuz0r

I agree. That looks better.

Changed 3 years ago by d1ffuz0r

Changed 3 years ago by claudep

comment:8 Changed 3 years ago by claudep

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 3 years ago by Claude Paroz <claude@…>

  • Resolution set to fixed
  • Status changed from new to closed

In b1ac329ba9bbcba90d8ced7e16909ed169b1d16e:

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

Thanks d1ffuz0r for helping with the patch.

comment:10 Changed 3 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 follow-up: Changed 19 months ago by maa@…

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

comment:12 in reply to: ↑ 11 Changed 19 months ago by bmispelon

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