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

NotSupportedError: Ordering can't span tables on MongoDB (content_type__app_label) #34

Closed
Jibola opened this issue May 21, 2024 · 2 comments · Fixed by #86
Closed

NotSupportedError: Ordering can't span tables on MongoDB (content_type__app_label) #34

Jibola opened this issue May 21, 2024 · 2 comments · Fixed by #86
Assignees

Comments

@Jibola
Copy link
Collaborator

Jibola commented May 21, 2024

Steps to reproduce

Followed instructions for initial setup from #18. Created my first admin account. From there, I called python manage.py makemigrations which worked. Afterward I then called python manage.py migrate which led to this initial error.

python manage.py migrate
Operations to perform:
  Apply all migrations: admin, auth, contenttypes, sessions
Running migrations:
  Applying admin.0004_alter_logentry_id... OK
  Applying auth.0013_alter_group_id_alter_permission_id_alter_user_id... OK
  Applying contenttypes.0003_alter_contenttype_id... OK
Traceback (most recent call last):
  File "/Users/jib/mongo/starterapp/storefront/manage.py", line 22, in <module>
    main()
  File "/Users/jib/mongo/starterapp/storefront/manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
    utility.execute()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/core/management/__init__.py", line 436, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/core/management/base.py", line 413, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/core/management/base.py", line 459, in execute
    output = self.handle(*args, **options)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/core/management/base.py", line 107, in wrapper
    res = handle_func(*args, **kwargs)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/core/management/commands/migrate.py", line 383, in handle
    emit_post_migrate_signal(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/core/management/sql.py", line 52, in emit_post_migrate_signal
    models.signals.post_migrate.send(
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/dispatch/dispatcher.py", line 189, in send
    response = receiver(signal=self, sender=sender, **named)
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/contrib/auth/management/__init__.py", line 91, in create_permissions
    all_perms = set(
                ^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/query.py", line 400, in __iter__
    self._fetch_all()
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django/db/models/query.py", line 1928, in _fetch_all
    self._result_cache = list(self._iterable_class(self))
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django_mongodb/compiler.py", line 47, in results_iter
    results = self.build_query(columns).fetch()
              ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django_mongodb/compiler.py", line 140, in build_query
    query.order_by(self._get_ordering())
                   ^^^^^^^^^^^^^^^^^^^^
  File "/opt/homebrew/Caskroom/miniforge/base/envs/django/lib/python3.12/site-packages/django_mongodb/compiler.py", line 170, in _get_ordering
    raise NotSupportedError("Ordering can't span tables on MongoDB (%s)." % order)
django.db.utils.NotSupportedError: Ordering can't span tables on MongoDB (content_type__app_label).
@timgraham
Copy link
Collaborator

We can't support ordering on related tables until we support joins. If we can't support joins (or until we can, if it'll be a longer-term goal), we could ignore ordering if it references a related table.

I temporarily worked around this in the Django fork by commenting out Permission.Meta.ordering.

@timgraham timgraham changed the title django.db.utils NotSupporteError: Ordering can't span tables on MongoDB (content_type__app_label) NotSupportedError: Ordering can't span tables on MongoDB (content_type__app_label) May 21, 2024
@Jibola
Copy link
Collaborator Author

Jibola commented May 21, 2024

We can't support ordering on related tables until we support joins. If we can't support joins (or until we can, if it'll be a longer-term goal), we could ignore ordering if it references a related table.

I temporarily worked around this in the Django fork by commenting out Permission.Meta.ordering.

Good to note. I'd say we will have to put strong efforts into support joins via the $lookup operator. That or we need to unpack all of the underlying join operations associated with the builtin admin package.

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

Successfully merging a pull request may close this issue.

2 participants