Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
fix empty and_query
  • Loading branch information
trollknurr committed May 15, 2015
commit 0906bf2c08e67eb43789ef976a784a4da01a08bc
12 changes: 7 additions & 5 deletions rest_framework/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,11 +107,13 @@ def filter_queryset(self, request, queryset, view):
for orm_lookup in orm_lookups]
and_queries.append(reduce(operator.or_, or_queries))

if settings.DATABASES[queryset.db]["ENGINE"] == "django.db.backends.oracle":
pk_list = queryset.filter(reduce(operator.and_, and_queries)).values_list('pk', flat=True)
return queryset.filter(pk__in=frozenset(pk_list))
else:
return queryset.filter(reduce(operator.and_, and_queries)).distinct()
if and_queries:
if settings.DATABASES[queryset.db]["ENGINE"] == "django.db.backends.oracle":
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll want a brief comment here regarding needing this behavior for oracle and distinct.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@tomchristie According to Oracle DB limits there is no capability to make a DISTINT on *LOB. There is a need to use SearchFilter with TextField (for example). That's why i pull this workaround for Oracle.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Clarification: I was meaning that we should have a code comment for this.

pk_list = queryset.filter(reduce(operator.and_, and_queries)).values_list('pk', flat=True)
return queryset.filter(pk__in=frozenset(pk_list))
else:
return queryset.filter(reduce(operator.and_, and_queries)).distinct()
return queryset


class OrderingFilter(BaseFilterBackend):
Expand Down