django-polymorphic icon indicating copy to clipboard operation
django-polymorphic copied to clipboard

Wrong manager when using call_command('dumpdata') in stead of python manage.py dumpdata

Open svleeuwen opened this issue 9 years ago • 8 comments

I'm using django.core.management.call_command('dumpdata') directly to export data dynamically. This should use the base_objects. It won't because it's only used when django/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.

svleeuwen avatar Jul 01 '15 16:07 svleeuwen

I have the same problem in my project.

zuck avatar Aug 20 '15 20:08 zuck

👍

fleur avatar Sep 08 '16 19:09 fleur

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?

toabi avatar Oct 27 '16 09:10 toabi

Okay, the main issue is that when I do call_command("dumpdata") in my own command, sys.argvis ['./myproject/manage.py', 'create_backup'] … so indeed it doesn't do this magic

toabi avatar Oct 27 '16 09:10 toabi

My workaround at the moment: not using call_command but subprocess.Popen to do dumpdata… it works :)

toabi avatar Oct 27 '16 11:10 toabi

@vdboor Would really appreciate a fix for this since we're using call_command('dumpdata') to create fixtures for testing.

ramonakira avatar Sep 07 '17 14:09 ramonakira

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')

dkellner avatar Mar 03 '20 06:03 dkellner