Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add embedded model support to loaddata / dumpdata #243

Open
timgraham opened this issue Jan 30, 2025 · 0 comments
Open

add embedded model support to loaddata / dumpdata #243

timgraham opened this issue Jan 30, 2025 · 0 comments
Assignees

Comments

@timgraham
Copy link
Collaborator

If an app contains an subclass of EmbeddedModel, dumpdata crashes:

$ python manage.py dumpdata embed --settings=mysite.mongo --traceback
[Traceback (most recent call last):
  File "/home/tim/code/mysite/manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/home/tim/code/django/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/home/tim/code/django/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/home/tim/code/django/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/home/tim/code/django/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/tim/code/django/django/core/management/commands/dumpdata.py", line 269, in handle
    serializers.serialize(
  File "/home/tim/code/django/django/core/serializers/__init__.py", line 134, in serialize
    s.serialize(queryset, **options)
  File "/home/tim/code/django/django/core/serializers/base.py", line 109, in serialize
    for count, obj in enumerate(queryset, start=1):
  File "/home/tim/code/django/django/core/management/commands/dumpdata.py", line 217, in get_objects
    queryset = objects.using(using).order_by(model._meta.pk.name)
               ^^^^^^^^^^^^^
AttributeError: 'EmbeddedModelManager' object has no attribute 'using'

If ignoring embedding models, embedded models incorrectly have only their string representation dumped:

$ python manage.py dumpdata embed --settings=mysite.mongo --exclude=embed.person --exclude=embed.address
[{"model": "embed.book", "pk": "67913fe312e1777e03b35af4", "fields": {"title": "Runaway Jury", "author": "Dan"}}]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant