-
-
Notifications
You must be signed in to change notification settings - Fork 7k
fix DISTINCT for Oracle databases #2935
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
Changes from 2 commits
7813d2f
c47ec60
de95598
0906bf2
745d8d0
e8b23c4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,6 +7,7 @@ | |
| from django.core.exceptions import ImproperlyConfigured | ||
| from django.db import models | ||
| from django.utils import six | ||
| from django.conf import settings | ||
| from rest_framework.compat import django_filters, guardian, get_model_name | ||
| from rest_framework.settings import api_settings | ||
| from functools import reduce | ||
|
|
@@ -104,8 +105,13 @@ def filter_queryset(self, request, queryset, view): | |
| for search_term in self.get_search_terms(request): | ||
| or_queries = [models.Q(**{orm_lookup: search_term}) | ||
| for orm_lookup in orm_lookups] | ||
| queryset = queryset.filter(reduce(operator.or_, or_queries)).distinct() | ||
| queryset = queryset.filter(reduce(operator.or_, or_queries)) | ||
|
|
||
| if settings.DATABASES[queryset.db]["ENGINE"] != "django.db.backends.oracle": | ||
| queryset = queryset.distinct() | ||
| else: | ||
| pk_list = queryset.values_list('pk', flat=True) | ||
| queryset = view.model.objects.filter(pk__in=set(pk_list)) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Side note here: Since when is the |
||
| return queryset | ||
|
|
||
|
|
||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd prefer it if we didn't introduce the
and_queries. We should keep each pull request as absolutely minimal as possible. Seems like there's two different changes here - the Oracle support as one, and the change in the filtering style as another. Let's just adopt the first of those two.Apologies for the slow progress on this, but thanks for getting it nearly there! :)