SmileyChris / django-countries

A Django application that provides country choices for use with forms, flag icons static files, and a country field for models.

Home Page:https://pypi.python.org/pypi/django-countries

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Django 5.0 breakage

bobort opened this issue · comments

I unintentionally upgraded to Django 5.0 trying to fix some other issues in my project, and I came across this error when rendering a country field in a template:

`'BlankChoiceIterator' object has no attribute 'len'

\Lib\site-packages\django_countries\widgets.py, line 29, in get_choices
class LazyChoicesMixin:
    def get_choices(self) -> ChoiceList:
        """
        When it's time to get the choices, if it was a lazy then figure it out
        now and memoize the result.
        """
        if isinstance(self._choices, Promise):
            self._choices: ChoiceList = list(self._choices)
                                            ^^^^^^^^^^^^^^^^^^^ …
        return self._choices
    def set_choices(self, value: ChoiceList):
        self._set_choices(value)
    choices = property(get_choices, set_choices)

Facing the same issue while using Django 5.0.

Fix is available but not merged: #438

So my local development environment is working, I removed the list() call from that line and it works for now, until the above fix is merged.

self._choices: ChoiceList = self._choices

At least while I'm working locally this will hold over

Same issue here. I tried @ml394 workaround and it works, thanks!

This is a problem for me as well. I'm already on django 5 and it's bringing down a few admin pages for me. Any news on when we can expect the fix to be merged?

This is happening for me as well, can't get the Admin pages to work properly anymore. Would love for the fix to be merged soon 🙂

same issue for me as well

Same issue here.

Same issue here also

@JulianTenschert @eatsleepdeploy @josepduarte and others: please stop spaming the issue with "Me too" comments. It's just filling everyone's inboxes and adding zero value. In the very first comment there is a thumb up emoticon you can use to express your interest in the issue.

just in case, here I found a temp patch until the actual fix gets released:
https://code.djangoproject.com/ticket/35046#comment:4

Fixed in the just-released v7.6 🥳

thanks, seems to be working!