Queryset field lookups for country code no longer works as of 7.3
chenyaoy opened this issue · comments
The change in 7.3, Make full English country names work in database lookups, for example, Person.objects.filter(country__icontains="zealand")
has caused queryset filter field lookups for the two character country code to no longer work.
For example, queryset.filter(country__regex=rf"^GB$")
would return results from my DB in 7.2.1, but in 7.3 and later it returns an empty queryset. I also tested that queryset.filter(country__contains="GB")
also incorrectly returns an empty queryset. However, queryset.filter(country="GB")
works as expected and so does queryset.filter(country__contains="Kingdom")
Yep, it's definitely an incompatible change (I really should have called it 8.0 I feel). It only changes the behaviour of advanced filters, because they don't really make a lot of sense against country codes - e.g. your example of __contains
has little practical benefits. Even __regex
I'd argue has limited benefits.
However it doesn't actually look difficult to make this work for the country code as well.
Maybe
django-countries/django_countries/fields.py
Lines 503 to 505 in aa0b5ee
F()
? That'd make it work for all the lookups and seems like a generally good improvement.
I'll leave this open so someone, if not me, will look closer at it some time. If you're really keen on this feature, feel free to try to implement that!