Open svleeuwen opened 9 years ago
I have the same problem in my project.
đź‘Ť
Spent an hour wondering why the dump exported via call_command
fails while the one created with manage.py dumpdata
works… Ugh. Any workaround available?
Okay, the main issue is that when I do call_command("dumpdata")
in my own command, sys.argv
is ['./myproject/manage.py', 'create_backup']
… so indeed it doesn't do this magic…
My workaround at the moment: not using call_command
but subprocess.Popen
to do dumpdata… it works :)
@vdboor Would really appreciate a fix for this since we're using call_command('dumpdata') to create fixtures for testing.
A better workaround might be to use patch
:
from unittest.mock import patch
@patch('sys.argv', ['./manage.py', 'dumpdata'])
def dump_json(self):
call_command('dumpdata', '--indent=2', '--output=dump.json')
I am not sure if this solved the original poster's problem, but I must say it assisted me greatly.
I'm using
django.core.management.call_command('dumpdata')
directly to export data dynamically. This should use thebase_objects
. It won't because it's only used whendjango/core/management/commands/dumpdata.py
is in the stack, which is a bit hacky. (https://github.com/chrisglass/django_polymorphic/blob/master/polymorphic/base.py#L244)I would be happy to help and fix this myself but maybe you could guide me how.