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

Change dummy queryset qualifier from "all" to "none" #1683

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

henryk
Copy link

@henryk henryk commented Aug 9, 2024

As is, django-filter is not compatible with django-scopes. Django-scopes is an additional guardrail which prevents accidental data exposure. It replaces the default manager of a model with a specialized manager that will refuse queries, unless a scope is active, that is there is a restriction along the critical dimensions are present.

This breaks most usages of the .all() queryset. But luckily, many usages that only care about the queryset itself and not the contents can be replaced with .none().

This pull request replaces the critical all usage with none. Nothing else is changed.

Example exception fixed by this PR:

 [...]
  File "venv\Lib\site-packages\django_filters\rest_framework\backends.py", line 51, in get_filterset_class
    class AutoFilterSet(self.filterset_base):
  File "venv\Lib\site-packages\django_filters\filterset.py", line 62, in __new__
    new_class.base_filters = new_class.get_filters()
                             ^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\django_filters\filterset.py", line 340, in get_filters
    filters[filter_name] = cls.filter_for_field(
                           ^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\django_filters\filterset.py", line 363, in filter_for_field
    field, lookup_type = resolve_field(field, lookup_expr)
                         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\django_filters\utils.py", line 204, in resolve_field
    query = model_field.model._default_manager.all().query
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "venv\Lib\site-packages\django_scopes\manager.py", line 94, in all
    a = a.all()
        ^^^^^^^
  File "venv\Lib\site-packages\django_scopes\manager.py", line 14, in error
    raise ScopeError("A scope on dimension(s) {} needs to be active for this query.".format(
django_scopes.exceptions.ScopeError: A scope on dimension(s) XXX needs to be active for this query.

Copy link

github-actions bot commented Aug 9, 2024

Coverage report

Click to see where and how coverage changed

FileStatementsMissingCoverageCoverage
(new stmts)
Lines missing
  django_filters
  utils.py
Project Total  

This report was generated by python-coverage-comment-action

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 this pull request may close these issues.

1 participant