Skip to content

Commit

Permalink
Fix attribute error when union queryset of safe delete model with oth…
Browse files Browse the repository at this point in the history
…ers (#152)

* Fix attribute error when union queryset of safe delete model with others

* Fix coveralls 422 Client Error
  • Loading branch information
yuekui authored Mar 15, 2021
1 parent cb8b320 commit 7bc29c2
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/python-app.yml
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ jobs:
- name: Coverage
if: ${{ success() }}
run: |
coveralls
coveralls --service=github
3 changes: 2 additions & 1 deletion safedelete/queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ def _combinator_query(self, combinator, *other_qs, **kwargs):
# Filter visibility for operations like union, difference and intersection
self._filter_visibility()
for qs in other_qs:
qs._filter_visibility()
if hasattr(qs, "_filter_visibility"):
qs._filter_visibility()
return super(SafeDeleteQueryset, self)._combinator_query(
combinator, *other_qs, **kwargs
)
Expand Down
22 changes: 22 additions & 0 deletions safedelete/tests/test_queryset.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,28 @@ def test_values_list(self):
QuerySetModel.objects.filter(id=instance.id).values_list('pk', flat=True)[0]
)

def test_union_with_different_models(self):
# Test the safe deleted model can union with other models."""
queryset = QuerySetModel.objects.values_list("pk")
other_queryset = OtherModel.objects.values_list("pk")
self.assertEqual(
queryset.union(other_queryset).count(),
1
)
self.assertEqual(
other_queryset.union(queryset).count(),
1
)
queryset = QuerySetModel.all_objects.values_list("pk")
self.assertEqual(
queryset.union(other_queryset, all=True).count(),
2
)
self.assertEqual(
other_queryset.union(queryset, all=True).count(),
2
)

def test_union(self):
# Test whether the soft deleted model can be found by union."""
queryset = QuerySetModel.objects.all()
Expand Down

0 comments on commit 7bc29c2

Please sign in to comment.