Skip to content

Commit

Permalink
Fix TypeError in CountryFilter.choices()
Browse files Browse the repository at this point in the history
When no country is selected, self.used_parameters.get(self.field.name)
will return None. This raises a TypeError when CountryFilter.choices()
tries to check whether a specific country choice is currently selected.

Avoid this by checking that the parameter is not empty similarly to how
Django's built-in admin.filters.RelatedFieldListFilter checks for this.

Fixes: 04662d1 ("Support Django 5.0")
  • Loading branch information
foutrelis committed Apr 1, 2024
1 parent 0a50fcd commit bae099f
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion django_countries/filters.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def choices(self, changelist):
}
for lookup, title in self.lookup_choices(changelist):
if django.VERSION >= (5, 0):
selected = force_str(lookup) in value
selected = value is not None and force_str(lookup) in value
else:
selected = force_str(lookup) == value
yield {
Expand Down

0 comments on commit bae099f

Please sign in to comment.