django-selectable icon indicating copy to clipboard operation
django-selectable copied to clipboard

Django-selectable incompatible with Django 4.0

Open ArkieCoder opened this issue 3 years ago • 1 comments

When using django-selectable with Django 4.0, the following error occurs on startup:

   File "/code/django_selectable/selectable/urls.py", line 1, in <module>
     from django.conf.urls import url
 ImportError: cannot import name 'url' from 'django.conf.urls' (/usr/local/lib/python3.10/site-packages/django/conf/urls/__init__.py)

This is due to the fact that django.conf.urls.url was finally removed from Django in 4.0 after being deprecated for some time in Django 3.x. More info here: https://forum.djangoproject.com/t/django-4-0-url-import-error/11065/5

I have found that this simple patch fixes this issue, and would like to submit it to the group for inclusion:

--- a/selectable/urls.py
+++ b/selectable/urls.py
@@ -1,8 +1,8 @@
-from django.conf.urls import url
+from django.urls import re_path
 
 from . import views
 
 
 urlpatterns = [
-    url(r'^(?P<lookup_name>[-\w]+)/$', views.get_lookup, name="selectable-lookup"),
+    re_path(r'^(?P<lookup_name>[-\w]+)/$', views.get_lookup, name="selectable-lookup"),
 ]

ArkieCoder avatar Jan 27 '22 19:01 ArkieCoder

If you'd just like to use the patch above and you're working within Docker, you can add these lines to your Dockerfile to apply the patch to what is installed via pip3. This example assumes you have django-selectable in your requirements.txt, and that the above patch is stored in the file ./patches/selectable-urls-py.gitpatch relative to your Dockerfile.

RUN pip3 install -r requirements.txt
RUN pip3 show django-selectable | \
    grep "^Location: " | sed -e "s/^Location: //g" > /tmp/dsloc.txt
COPY ./patches/selectable-urls-py.gitpatch /tmp
RUN cp /tmp/selectable-urls-py.gitpatch `cat /tmp/dsloc.txt`
RUN cd `cat /tmp/dsloc.txt` && git apply selectable-urls-py.gitpatch

If you're not running via Docker, in your build process right after you install requirements using pip3, you can use something like this shell script:

#!/usr/bin/env bash
virtualenv /home/ubuntu/app/venv
source /home/ubuntu/app/venv/bin/activate
DSLOC=`pip3 show django-selectable | \
  grep "^Location: " | sed -e "s/^Location: //g"` 
cd $DSLOC && git apply /home/ubuntu/app/patches/selectable-urls-py.gitpatch

It should be noted that the patch above is a result of a git diff and that's why I'm using git apply to apply it, because patch requires some additional processing of git diffs in order to function properly.

ArkieCoder avatar Jan 28 '22 13:01 ArkieCoder

Are there plans to merge this #222? Is it that it's still pending for review, or simply there's no maintainer anymore? I'll be willing to help in any way to push this forward.

luisperlaz avatar Oct 18 '22 07:10 luisperlaz

Just wondering if there are any actively maintained alternatives to Django-Selectable that support Django 4.*?

aitoehigie avatar Feb 23 '23 13:02 aitoehigie

released v1.4

domdinicola avatar Jun 22 '23 11:06 domdinicola