Skip to content

Commit 7bc29c2

Browse files
authored
Fix attribute error when union queryset of safe delete model with others (#152)
* Fix attribute error when union queryset of safe delete model with others * Fix coveralls 422 Client Error
1 parent cb8b320 commit 7bc29c2

File tree

3 files changed

+25
-2
lines changed

3 files changed

+25
-2
lines changed

.github/workflows/python-app.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,4 +57,4 @@ jobs:
5757
- name: Coverage
5858
if: ${{ success() }}
5959
run: |
60-
coveralls
60+
coveralls --service=github

safedelete/queryset.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,8 @@ def _combinator_query(self, combinator, *other_qs, **kwargs):
153153
# Filter visibility for operations like union, difference and intersection
154154
self._filter_visibility()
155155
for qs in other_qs:
156-
qs._filter_visibility()
156+
if hasattr(qs, "_filter_visibility"):
157+
qs._filter_visibility()
157158
return super(SafeDeleteQueryset, self)._combinator_query(
158159
combinator, *other_qs, **kwargs
159160
)

safedelete/tests/test_queryset.py

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,28 @@ def test_values_list(self):
210210
QuerySetModel.objects.filter(id=instance.id).values_list('pk', flat=True)[0]
211211
)
212212

213+
def test_union_with_different_models(self):
214+
# Test the safe deleted model can union with other models."""
215+
queryset = QuerySetModel.objects.values_list("pk")
216+
other_queryset = OtherModel.objects.values_list("pk")
217+
self.assertEqual(
218+
queryset.union(other_queryset).count(),
219+
1
220+
)
221+
self.assertEqual(
222+
other_queryset.union(queryset).count(),
223+
1
224+
)
225+
queryset = QuerySetModel.all_objects.values_list("pk")
226+
self.assertEqual(
227+
queryset.union(other_queryset, all=True).count(),
228+
2
229+
)
230+
self.assertEqual(
231+
other_queryset.union(queryset, all=True).count(),
232+
2
233+
)
234+
213235
def test_union(self):
214236
# Test whether the soft deleted model can be found by union."""
215237
queryset = QuerySetModel.objects.all()

0 commit comments

Comments
 (0)