Skip to content

Commit

Permalink
🐛 [BUG] Prevent objects from being returned several times in APIv2 by…
Browse files Browse the repository at this point in the history
… filtering on ManyToMany (refs #4448)
  • Loading branch information
Chatewgne committed Jan 14, 2025
1 parent c0de8ff commit ad15791
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 1 deletion.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ CHANGELOG
- Move Treks' accessibility pictures into the attached files tab (refs #2967)
- Removes the display of an object's structure in its properties tab title

**Bug fixes**

- Prevent objects from being returned several times in APIv2 by filtering on ManyToMany (#4448)

**Documentation**

- Update theme color
Expand Down
7 changes: 7 additions & 0 deletions geotrek/api/tests/test_v2.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,13 @@ def test_trek_theme_filter(self):
json_response = response.json()
self.assertEqual(len(json_response.get('results')), 0)

# Test result is not duplicated
self.parent.themes.add(self.theme3)
response = self.get_trek_list({'themes': f"{self.theme2.pk},{self.theme3.pk}"})
self.assertEqual(response.status_code, 200)
json_response = response.json()
self.assertEqual(len(json_response.get('results')), 1)

def test_trek_portal_filter(self):
response = self.get_trek_list({'portals': self.portal.pk})
# test response code
Expand Down
2 changes: 1 addition & 1 deletion geotrek/api/v2/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -743,7 +743,7 @@ def filter_queryset(self, request, queryset, view):
Q(name__icontains=q) | Q(description__icontains=q)
| Q(description_teaser__icontains=q) | Q(ambiance__icontains=q)
)
return qs
return qs.distinct()

def get_schema_fields(self, view):
return (
Expand Down

0 comments on commit ad15791

Please sign in to comment.