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

Bug: Deprecated function call breaking manage.py collectstatic --noinput #310

Closed
gganeshan opened this issue Dec 3, 2019 · 13 comments
Closed

Comments

@gganeshan
Copy link

gganeshan commented Dec 3, 2019

It seems like django deprecated admin_static which is causing the following exception when running manage.py collectstatic --noinput command.

Is there a way to resolve this exception??

Some posts suggest uninstalling and reinstalling django which I tried with no luck.

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/django/template/utils.py", line 66, in __getitem__
    return self._engines[alias]
KeyError: 'django'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/usr/lib/python3.7/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
    module = import_module(entry[1])
  File "/usr/lib/python3.7/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/usr/lib/python3.7/site-packages/django/contrib/admin/templatetags/admin_static.py", line 5, in <module>
    from django.utils.deprecation import RemovedInDjango30Warning
ImportError: cannot import name 'RemovedInDjango30Warning' from 'django.utils.deprecation' (/usr/lib/python3.7/site-packages/django/utils/deprecation.py)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "manage.py", line 10, in <module>
    execute_from_command_line(sys.argv)
  File "/usr/lib/python3.7/site-packages/django/core/management/__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "/usr/lib/python3.7/site-packages/django/core/management/__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "/usr/lib/python3.7/site-packages/django/core/management/base.py", line 328, in run_from_argv
    self.execute(*args, **cmd_options)
  File "/usr/lib/python3.7/site-packages/django/core/management/base.py", line 369, in execute
    output = self.handle(*args, **options)
  File "/usr/lib/python3.7/site-packages/compressor/management/commands/compress.py", line 277, in handle
    self.handle_inner(**options)
  File "/usr/lib/python3.7/site-packages/compressor/management/commands/compress.py", line 300, in handle_inner
    offline_manifest, block_count, results = self.compress(engine, extensions, verbosity, follow_links, log)
  File "/usr/lib/python3.7/site-packages/compressor/management/commands/compress.py", line 100, in compress
    if not self.get_loaders():
  File "/usr/lib/python3.7/site-packages/compressor/management/commands/compress.py", line 50, in get_loaders
    for e in engines.all():
  File "/usr/lib/python3.7/site-packages/django/template/utils.py", line 90, in all
    return [self[alias] for alias in self]
  File "/usr/lib/python3.7/site-packages/django/template/utils.py", line 90, in <listcomp>
    return [self[alias] for alias in self]
  File "/usr/lib/python3.7/site-packages/django/template/utils.py", line 81, in __getitem__
    engine = engine_cls(params)
  File "/usr/lib/python3.7/site-packages/django/template/backends/django.py", line 25, in __init__
    options['libraries'] = self.get_templatetag_libraries(libraries)
  File "/usr/lib/python3.7/site-packages/django/template/backends/django.py", line 43, in get_templatetag_libraries
    libraries = get_installed_libraries()
  File "/usr/lib/python3.7/site-packages/django/template/backends/django.py", line 108, in get_installed_libraries
    for name in get_package_libraries(pkg):
  File "/usr/lib/python3.7/site-packages/django/template/backends/django.py", line 125, in get_package_libraries
    "trying to load '%s': %s" % (entry[1], e)
django.template.library.InvalidTemplateLibrary: Invalid template library specified. ImportError raised when trying to load 'django.contrib.admin.templatetags.admin_static': cannot import name 'RemovedInDjango30Warning' from 'django.utils.deprecation' (/usr/lib/python3.7/site-packages/django/utils/deprecation.py)

Reference: https://django.readthedocs.io/en/2.2.x/releases/2.1.html#id2

@gganeshan
Copy link
Author

Figured a way to resolve this issue.

My containerized application installs a number of additional libraries, one of them being django-auth-ldap.

This library has an implicit constraint defined as Django>=1.11 so it installs Django v3.0 leading to this issue.

I added a constraint to my pip install limiting Django version at <3.0 for now.

constraints.txt

django<3.0

pip install django-auth-ldap -c constraints.txt

@cuu508
Copy link
Member

cuu508 commented Dec 4, 2019

I plan to update the project to use Django 3 soon. So the above exception might become a problem again.

Just tried to reproduce the problem, but no luck so far. I installed Django==3.0.0 and ran manage.py collectstatic --noinput but no errors here...

In what order did you install the libraries?

@gganeshan
Copy link
Author

I plan to update the project to use Django 3 soon. So the above exception might become a problem again.

Ack

In what order did you install the libraries?

First pip3 install -r requirements.txt - where requirements.txt is the same as https://github.com/healthchecks/healthchecks/blob/master/requirements.txt

then pip3 install django-auth-ldap

In the first step I observed that Django 2.2.8 is installed as expected. However, in the second step it gets upgraded to Django 3.0.

Let me know if you are still not able to reproduce the issue.

@SuperSandro2000
Copy link
Contributor

You didn't supply --update? Normally Django>=1.11 should be finde with 2.X. See https://github.com/django-auth-ldap/django-auth-ldap/blob/master/setup.cfg#L39

@cuu508
Copy link
Member

cuu508 commented Dec 5, 2019

Still haven't managed to reproduce it. There's this bit in the traceback you posted:

File "/usr/lib/python3.7/site-packages/django/contrib/admin/templatetags/admin_static.py", line 5, in <module>

admin_static.py file does not exist in Django 3. It only exists in Django 2.x (and is supposed to throw a deprecation warning).

My hunch is that you have both Django 2.x and Django 3 intalled in different locations, and these are somehow getting mixed up. If you use virtualenv, maybe you have Django installed both globally and inside a virtualenv?

I've also sometimes had to manually remove outdated .pyc files – but if pip installation goes cleanly, pip should have taken care of that I think.

@gganeshan
Copy link
Author

My hunch is that you have both Django 2.x and Django 3 intalled in different locations, and these are somehow getting mixed up. If you use virtualenv, maybe you have Django installed both globally and inside a virtualenv?

My app is containerized so these steps are taking place during the build process.

As I mentioned earlier, when I run pip3 install -r requirements.txt it installs django 2.2.8 as defined here and then when I run pip3 install django-auth-ldap it simply installs django 3.0 on top of it (without pip uninstalling django) which I believe is leading to this error.

@cuu508
Copy link
Member

cuu508 commented Dec 5, 2019

Could you share the Dockerfile (with any sensitive or unrelated bits stripped out) you are using for building the container?

@gganeshan
Copy link
Author

You didn't supply --update? Normally Django>=1.11 should be finde with 2.X

no I did not.
I could clearly see in my build output that it was installing django 3.X (see below).

django install:

  Collecting Django==2.2.8 (from -r requirements.txt (line 2))
  Downloading https://internal-pip-mirror/api/pypi/pypi-python/packages/packages/b2/79/df0ffea7bf1e02c073c2633702c90f4384645c40a1dd09a308e02ef0c817/Django-2.2.8-py3-none-any.whl (7.5MB)

django-auth-ldap install:

Collecting Django>=1.11 (from django-auth-ldap)
  Downloading https://internal-pip-mirror/api/pypi/pypi-python/packages/packages/43/d6/0aed0b12c66527748ce5a007da4618a65dfbe1f8fca82eccedf57d60295f/Django-3.0-py3-none-any.whl (7.4MB)

@gganeshan
Copy link
Author

Could you share the Dockerfile (with any sensitive or unrelated bits stripped out) you are using for building the container?

Sure will do in a few.

@SuperSandro2000
Copy link
Contributor

I could reproduce it:

docker run debian:sid-slim

apt update
apt install python3-pip libldap2-dev libpq-dev libsasl2-dev
pip3 install -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt
pip3 install django-auth-ldap

@gganeshan
Copy link
Author

I could reproduce it:

thanks @SuperSandro2000

@cuu508
Copy link
Member

cuu508 commented Dec 5, 2019

@SuperSandro2000 I ran the same commands. Here's the output of pip3 commands:

root@bca4853a5e37:/# pip3 install -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt
Collecting croniter==0.3.30 (from -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/c8/4c/04dea44f87b963d5c3f2bbc391e6c69d0a14aa896e35590be56213a04e4f/croniter-0.3.30-py2.py3-none-any.whl
Collecting Django==2.2.8 (from -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/d3/d0/ef75c788627f4218a8d08dccdf4ebc91f5b83c48d09ec8f2a3db9610014b/Django-2.2.8-py3-none-any.whl (7.5MB)
    100% |████████████████████████████████| 7.5MB 151kB/s 
Collecting django_compressor==2.3 (from -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/43/e2/50e21afd7e13b522f7d1a29cf0a6dd65e19835950dce3be3c5928e668846/django_compressor-2.3-py2.py3-none-any.whl (124kB)
    100% |████████████████████████████████| 133kB 940kB/s 
Collecting psycopg2==2.8.3 (from -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 4))
  Downloading https://files.pythonhosted.org/packages/5c/1c/6997288da181277a0c29bc39a5f9143ff20b8c99f2a7d059cfb55163e165/psycopg2-2.8.3.tar.gz (377kB)
    100% |████████████████████████████████| 378kB 312kB/s 
Collecting pytz==2019.1 (from -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 5))
  Downloading https://files.pythonhosted.org/packages/3d/73/fe30c2daaaa0713420d0382b16fbb761409f532c56bdcc514bf7b6262bb6/pytz-2019.1-py2.py3-none-any.whl (510kB)
    100% |████████████████████████████████| 512kB 552kB/s 
Collecting requests==2.22.0 (from -r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/51/bd/23c926cd341ea6b7dd0b2a00aba99ae0f828be89d72b2190f27c11d4b7fb/requests-2.22.0-py2.py3-none-any.whl (57kB)
    100% |████████████████████████████████| 61kB 962kB/s 
Collecting python-dateutil (from croniter==0.3.30->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 1))
  Downloading https://files.pythonhosted.org/packages/d4/70/d60450c3dd48ef87586924207ae8907090de0b306af2bce5d134d78615cb/python_dateutil-2.8.1-py2.py3-none-any.whl (227kB)
    100% |████████████████████████████████| 235kB 844kB/s 
Collecting sqlparse (from Django==2.2.8->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 2))
  Downloading https://files.pythonhosted.org/packages/ef/53/900f7d2a54557c6a37886585a91336520e5539e3ae2423ff1102daf4f3a7/sqlparse-0.3.0-py2.py3-none-any.whl
Collecting django-appconf>=1.0 (from django_compressor==2.3->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/f6/b3/fcec63afcf323581c4919f21e90ef8c8200034108a6a0ab47a6bf6a9327b/django_appconf-1.0.3-py2.py3-none-any.whl
Collecting rcssmin==1.0.6 (from django_compressor==2.3->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/e2/5f/852be8aa80d1c24de9b030cdb6532bc7e7a1c8461554f6edbe14335ba890/rcssmin-1.0.6.tar.gz (582kB)
    100% |████████████████████████████████| 583kB 682kB/s 
Collecting rjsmin==1.1.0 (from django_compressor==2.3->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 3))
  Downloading https://files.pythonhosted.org/packages/92/7d/42f2b54257ed8a2904b82f7b368afbea2206e4f43311557d410a84730a15/rjsmin-1.1.0-cp37-cp37m-manylinux1_x86_64.whl
Collecting urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 (from requests==2.22.0->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/b4/40/a9837291310ee1ccc242ceb6ebfd9eb21539649f193a7c8c86ba15b98539/urllib3-1.25.7-py2.py3-none-any.whl (125kB)
    100% |████████████████████████████████| 133kB 1.7MB/s 
Collecting certifi>=2017.4.17 (from requests==2.22.0->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/b9/63/df50cac98ea0d5b006c55a399c3bf1db9da7b5a24de7890bc9cfd5dd9e99/certifi-2019.11.28-py2.py3-none-any.whl (156kB)
    100% |████████████████████████████████| 163kB 1.7MB/s 
Collecting chardet<3.1.0,>=3.0.2 (from requests==2.22.0->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/bc/a9/01ffebfb562e4274b6487b4bb1ddec7ca55ec7510b22e4c51f14098443b8/chardet-3.0.4-py2.py3-none-any.whl (133kB)
    100% |████████████████████████████████| 143kB 1.8MB/s 
Collecting idna<2.9,>=2.5 (from requests==2.22.0->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 6))
  Downloading https://files.pythonhosted.org/packages/14/2c/cd551d81dbe15200be1cf41cd03869a46fe7226e7450af7a6545bfc474c9/idna-2.8-py2.py3-none-any.whl (58kB)
    100% |████████████████████████████████| 61kB 928kB/s 
Requirement already satisfied: six>=1.5 in /usr/lib/python3/dist-packages (from python-dateutil->croniter==0.3.30->-r https://github.com/healthchecks/healthchecks/raw/master/requirements.txt (line 1)) (1.13.0)
Building wheels for collected packages: psycopg2, rcssmin
  Running setup.py bdist_wheel for psycopg2 ... done
  Stored in directory: /root/.cache/pip/wheels/48/06/67/475967017d99b988421b87bf7ee5fad0dad789dc349561786b
  Running setup.py bdist_wheel for rcssmin ... done
  Stored in directory: /root/.cache/pip/wheels/f5/82/85/01af385ab989b89e49bbe1d23047a8766ad43e1ebdad5084ed
Successfully built psycopg2 rcssmin
Installing collected packages: python-dateutil, croniter, sqlparse, pytz, Django, django-appconf, rcssmin, rjsmin, django-compressor, psycopg2, urllib3, certifi, chardet, idna, requests
Successfully installed Django-2.2.8 certifi-2019.11.28 chardet-3.0.4 croniter-0.3.30 django-appconf-1.0.3 django-compressor-2.3 idna-2.8 psycopg2-2.8.3 python-dateutil-2.8.1 pytz-2019.1 rcssmin-1.0.6 requests-2.22.0 rjsmin-1.1.0 sqlparse-0.3.0 urllib3-1.25.7
root@bca4853a5e37:/# pip3 install django-auth-ldap
Collecting django-auth-ldap
  Downloading https://files.pythonhosted.org/packages/e0/3f/ed83151177789fd44e6ed2cb569eeea3c4198f4321690ffe969afe61e909/django_auth_ldap-2.1.0-py3-none-any.whl
Requirement already satisfied: Django>=1.11 in /usr/local/lib/python3.7/dist-packages (from django-auth-ldap) (2.2.8)
Collecting python-ldap>=3.1 (from django-auth-ldap)
  Downloading https://files.pythonhosted.org/packages/ea/93/596f875e003c770447f4b99267820a0c769dd2dc3ae3ed19afe460fcbad0/python-ldap-3.2.0.tar.gz (367kB)
    100% |████████████████████████████████| 368kB 574kB/s 
Requirement already satisfied: sqlparse in /usr/local/lib/python3.7/dist-packages (from Django>=1.11->django-auth-ldap) (0.3.0)
Requirement already satisfied: pytz in /usr/local/lib/python3.7/dist-packages (from Django>=1.11->django-auth-ldap) (2019.1)
Collecting pyasn1>=0.3.7 (from python-ldap>=3.1->django-auth-ldap)
  Downloading https://files.pythonhosted.org/packages/62/1e/a94a8d635fa3ce4cfc7f506003548d0a2447ae76fd5ca53932970fe3053f/pyasn1-0.4.8-py2.py3-none-any.whl (77kB)
    100% |████████████████████████████████| 81kB 1.2MB/s 
Collecting pyasn1_modules>=0.1.5 (from python-ldap>=3.1->django-auth-ldap)
  Downloading https://files.pythonhosted.org/packages/52/50/bb4cefca37da63a0c52218ba2cb1b1c36110d84dcbae8aa48cd67c5e95c2/pyasn1_modules-0.2.7-py2.py3-none-any.whl (131kB)
    100% |████████████████████████████████| 133kB 728kB/s 
Building wheels for collected packages: python-ldap
  Running setup.py bdist_wheel for python-ldap ... done
  Stored in directory: /root/.cache/pip/wheels/48/dd/0b/a06d1baf6575ad4520fc1fcf5bd96b493cd89670fdf6ade224
Successfully built python-ldap
Installing collected packages: pyasn1, pyasn1-modules, python-ldap, django-auth-ldap
Successfully installed django-auth-ldap-2.1.0 pyasn1-0.4.8 pyasn1-modules-0.2.7 python-ldap-3.2.0
root@bca4853a5e37:/# pip3 freeze
asn1crypto==0.24.0
certifi==2019.11.28
chardet==3.0.4
croniter==0.3.30
cryptography==2.6.1
dbus-python==1.2.14
Django==2.2.8
django-appconf==1.0.3
django-auth-ldap==2.1.0
django-compressor==2.3
entrypoints==0.3
idna==2.8
keyring==18.0.1
keyrings.alt==3.1.1
psycopg2==2.8.3
pyasn1==0.4.8
pyasn1-modules==0.2.7
pycrypto==2.6.1
PyGObject==3.34.0
python-dateutil==2.8.1
python-ldap==3.2.0
pytz==2019.1
pyxdg==0.26
rcssmin==1.0.6
requests==2.22.0
rjsmin==1.1.0
SecretStorage==2.3.1
six==1.13.0
sqlparse==0.3.0
urllib3==1.25.7

Installing django-auth-ldap didn't trigger a Django update for me. I'm probably missing something obvious but not sure what it is...

@SuperSandro2000
Copy link
Contributor

You are right. Can't read the output properly.

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

3 participants