Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ChainedModelChoiceField.choices initialization incompatibility with Django 5.0 #353

Open
7 tasks done
Dmitri-Sintsov opened this issue Dec 8, 2023 · 11 comments
Open
7 tasks done

Comments

@Dmitri-Sintsov
Copy link

Dmitri-Sintsov commented Dec 8, 2023

Checklist

  • This issue is not about installing previous versions of django-smart-selects older than 1.2.8. I understand that previous versions are insecure and will not receive any support whatsoever.
  • I have verified that that issue exists against the master branch of django-smart-selects.
  • I have searched for similar issues in both open and closed tickets and cannot find a duplicate.
  • I have debugged the issue to the smart_selects app.
  • I have reduced the issue to the simplest possible case.
  • I have included all relevant sections of models.py, forms.py, and views.py with problems.
  • I have used GitHub Flavored Markdown to style all of my posted code.

Steps to reproduce

The following error is being produced while the initialization of Django 5.0 project:

 File "/home/user/work/ispdevenv/lib/python3.10/site-packages/smart_selects/db_fields.py", line 8, in <module>
    from smart_selects import form_fields
  File "/home/user/work/ispdevenv/lib/python3.10/site-packages/smart_selects/form_fields.py", line 10, in <module>
    class ChainedModelChoiceField(ModelChoiceField):
  File "/home/user/work/ispdevenv/lib/python3.10/site-packages/smart_selects/form_fields.py", line 62, in ChainedModelChoiceField
    choices = property(_get_choices, ChoiceField._set_choices)
AttributeError: type object 'ChoiceField' has no attribute '_set_choices'

Actual behavior

Impossible to initialize ChainedModelChoiceField.choices.

Expected behavior

Used to work fine with Django<5.0

See django/django@500e010 for the reference.

@djruesch
Copy link

Anyone have an ETA when this will be fixed for Django 5.0+

@lguariento
Copy link

Hello, same issue here. Is there a temporary workaround at least?

@lguariento
Copy link

I have renamed ChoiceField._set_choices into ChoiceField.choices. That did the trick!

@rickylenon
Copy link

rickylenon commented Apr 6, 2024

I have renamed ChoiceField._set_choices into ChoiceField.choices. That did the trick!

This works with me. But i get error:
bool' object has no attribute 'startswith'

My workaround is to change something under class JqueryMediaMixin
line 50:
...
media += Media(js=js)
return media

replace with:
..make sure js is string type..
if isinstance(js, str):
media += Media(js=js)
return media

now it works!

PS:
File to edit:
..site-packages/smart_selects/widgets.py

@yardensachs
Copy link

yardensachs commented Apr 6, 2024

its fixed in 1.7.1, but v1.7.1 is not in pypi, you need to install from github

@Sinanaltundag
Copy link

Sinanaltundag commented May 24, 2024

its fixed in 1.7.1, but v1.7.1 is not in pypi, you need to install from github

I install 1.7.1 from github but it has a problem on django admin

Django Version: | 5.0.6
NoReverseMatch
Reverse for 'chained_filter' not found. 'chained_filter' is not a valid view function or pattern name.
C:...\Lib\site-packages\django\urls\resolvers.py, line 851, in _reverse_with_prefix
django.contrib.admin.options.change_view
C:...\Scripts\python.exe
3.11.3

@lguariento
Copy link

Have you had a look at this?

@Sinanaltundag
Copy link

Thanks for explanation. @lguariento

Additionally I think documentation must be updated. installation progress is very old. for django 5;

for settings.py

USE_DJANGO_JQUERY = True

for urls.py

urlpatterns = [
    path("admin/", admin.site.urls),
    path('smart_selects/', include('smart_selects.urls')),
]

@aijazmahdavi
Copy link

I have renamed ChoiceField._set_choices into ChoiceField.choices. That did the trick!

this has an issue, if we are working on local and live then u need to edit files in env which is not recommended

@lguariento
Copy link

lguariento commented Jun 7, 2024

Of course, it's just a temporary workaround. Hopefully it'll be officially fixed soon.

@hernansaa
Copy link

@lguariento @Sinanaltundag you guys just have fixed all my problems. thanks a lot!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants