jazzband / django-polymorphic

Improved Django model inheritance with automatic downcasting
https://django-polymorphic.readthedocs.io
Other
1.65k stars 279 forks source link

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

Open svleeuwen opened 9 years ago

svleeuwen commented 9 years ago

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.

zuck commented 9 years ago

I have the same problem in my project.

fleur commented 8 years ago

đź‘Ť

toabi commented 8 years ago

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 commented 8 years ago

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 commented 8 years ago

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

ramonakira commented 7 years ago

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

dkellner commented 4 years ago

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')
vashanti commented 2 months ago

I am not sure if this solved the original poster's problem, but I must say it assisted me greatly.