2021年11月22日に、Release v5.0.0 · stephenmcd/mezzanine がリリースされています。
このブログは、Mezzanine 4.3.1
を使用しており、Upgradeを実施しました。実施した結果を記載します。
前提
以下の環境で実施しています。
- OS
cat /etc/redhat-release
CentOS Linux release 7.9.2009 (Core)
- Python Version
python3.6 -V
Python 3.6.7
- Package
python3.6 -m pip list | grep Django
Django 1.11.20
python3.6 -m pip list | grep Mezzanine
Mezzanine 4.3.1
Upgrade
Upgrade作業を実施します。
現状 Version の確認
UPGRADE 前の pip listの結果です。
python3.6 -m pip list
Package Version
-------------------------- ---------
beautifulsoup4 4.7.1
bleach 3.1.0
cachetools 3.1.0
certifi 2019.3.9
chardet 3.0.4
coreapi 2.3.3
coreschema 0.0.4
cssmin 0.2.0
Django 1.11.20
django-appconf 1.0.3
django-contrib-comments 1.9.1
django-cookies-samesite 0.2.0
django-critical 0.1.1
django-crontab 0.7.1
django-csp 3.5
django-csp-reports 1.2
django-extensions 2.1.6
django-filter 2.1.0
django-geoip2-extras 1.1.2
django-guess 0.0.1
django-health-check 3.12.1
django-htmlmin 0.11.0
django-oauth-toolkit 1.1.3
django-recaptcha 2.0.6
django-request 1.5.4
django-rest-swagger 2.2.0
django-robots 3.1.0
django-webpack-loader 0.6.0
djangorestframework 3.9.2
filebrowser-safe 0.5.0
future 0.17.1
geoip2 2.9.0
get 2019.4.13
google-api-python-client 1.7.8
google-auth 1.6.3
google-auth-httplib2 0.0.3
Google2Pandas 0.1.1
grappelli-safe 0.5.2
html5lib 1.0.1
httplib2 0.12.3
idna 2.8
itypes 1.1.0
Jinja2 2.10.1
Markdown 3.1
MarkupSafe 1.1.1
maxminddb 2.0.2
mecab-python3 0.996.2
Mezzanine 4.3.1
mezzanine-api 0.7.1
mezzanine-pagedown 1.3
mezzanine-pubsubhubbub-pub 0.0.5
mock 2.0.0
numpy 1.16.3
oauth2client 4.1.3
oauthlib 3.0.1
openapi-codec 1.3.2
pandas 0.24.2
pbr 5.1.3
Pillow 6.0.0
pip 21.3.1
post 2019.4.13
psutil 5.7.2
psycopg2 2.8.2
public 2019.4.13
pyasn1 0.4.5
pyasn1-modules 0.2.5
Pygments 2.3.1
pymdown-extensions 6.0
python-dateutil 2.8.0
python-memcached 1.59
pytz 2019.1
query-string 2019.4.13
request 2019.4.13
requests 2.21.0
requests-oauthlib 1.2.0
rsa 4.0
scikit-learn 0.20.3
scipy 1.2.1
setuptools 39.0.1
simplejson 3.16.0
six 1.12.0
soupsieve 1.9.1
tzlocal 1.5.1
uritemplate 3.0.0
urllib3 1.24.2
webencodings 0.5.1
UPGRADE実行
以下、コマンドでUpgradeを実施しました。
python3.6 -m pip install Mezzanine -U
...
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
django-csp-reports 1.2 requires django<2.0.99,>=1.8, but you have django 3.2.10 which is incompatible.
Successfully installed Mezzanine-5.0.0 asgiref-3.4.1 backports.zoneinfo-0.2.1 chardet-4.0.0 charset-normalizer-2.0.9 django-3.2.10 filebrowser-safe-1.0.0 grappelli-safe-1.0.0 importlib-resources-5.4.0 pillow-8.4.0 pytz-deprecation-shim-0.1.0.post0 requests-2.26.0 requests-oauthlib-1.3.0 sqlparse-0.4.2 typing-extensions-4.0.1 tzdata-2021.5 tzlocal-4.1 zipp-3.6.0
django-csp-reports 1.2 が、django3.2.10 に対して互換性がなさそうなエラーが出力されたので、django-csp-reportsのUpgradeも合わせて実施しました。
python3.6 -m pip install django-csp-reports -U
Installing collected packages: django-csp-reports
Attempting uninstall: django-csp-reports
Found existing installation: django-csp-reports 1.2
Uninstalling django-csp-reports-1.2:
Successfully uninstalled django-csp-reports-1.2
Running setup.py install for django-csp-reports ... done
Successfully installed django-csp-reports-1.6
check コマンドによる確認
Django の check コマンド エラーとならないか確認します。
ImportError: cannot import name 'python_2_unicode_compatible'
複数のモジュールで、importエラーが発生しました。
これは、Django 3.x でPython2互換のためのAPIが削除されたことが影響しています。
Django 3.0 release notes | Django documentation | Django
python3.6 manage.py check
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/robots/models.py", line 3, in <module>
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible'
python3.6 manage.py check
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django_comments/models.py", line 4, in <module>
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible'
python3.6 manage.py check
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/request/models.py", line 9, in <module>
from django.utils.encoding import python_2_unicode_compatible
ImportError: cannot import name 'python_2_unicode_compatible'
python3.6 -m pip install django-robots -U
python3.6 -m pip install django-request -U
python3.6 -m pip install django-contrib-comments -U
ModuleNotFoundError: No module named 'django.core.urlresolvers'
python3.6 manage.py check
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/mezzanine_pubsubhubbub_pub/models.py", line 20, in <module>
from django.core.urlresolvers import reverse
ModuleNotFoundError: No module named 'django.core.urlresolvers'
reverse
は、Django 2.0から django.core.urlresolvers
配下から、django.urls
配下に移動したようです。 以下のStack Overflow の記事が参考になりました。
python - ImportError: No module named ‘django.core.urlresolvers’ - Stack Overflow
ImportError: cannot import name 'six'
Traceback (most recent call last):
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/template/backends/django.py", line 121, in get_package_libraries
module = import_module(entry[1])
File "/usr/lib64/python3.6/importlib/__init__.py", line 126, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 994, in _gcd_import
File "<frozen importlib._bootstrap>", line 971, in _find_and_load
File "<frozen importlib._bootstrap>", line 955, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 665, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 678, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/rest_framework/templatetags/rest_framework.py", line 9, in <module>
from django.utils import six
ImportError: cannot import name 'six'
ImportError: cannot import name ‘six’ from ‘django.utils’ - Qiita
djangorestframeworkの最新化でエラーは解消しました。
python3.6 -m pip install djangorestframework -U
ModuleNotFoundError: No module named 'django_pylibmc'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "manage.py", line 14, in <module>
execute_from_command_line(sys.argv)
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
utility.execute()
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/management/__init__.py", line 413, in execute
self.fetch_command(subcommand).run_from_argv(self.argv)
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/management/base.py", line 354, in run_from_argv
self.execute(*args, **cmd_options)
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/management/base.py", line 398, in execute
output = self.handle(*args, **options)
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/management/commands/check.py", line 69, in handle
databases=options['databases'],
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/management/base.py", line 423, in check
databases=databases,
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/checks/registry.py", line 76, in run_checks
new_errors = check(app_configs=app_configs, databases=databases)
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/checks/caches.py", line 63, in check_file_based_cache_is_absolute
cache = caches[alias]
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/var/www/python-venv/blog/.venv/lib64/python3.6/site-packages/django/core/cache/__init__.py", line 43, in create_connection
) from e
django.core.cache.backends.base.InvalidCacheBackendError: Could not find backend 'django_pylibmc.memcached.PyLibMCCache': No module named 'django_pylibmc'
````
`Memcached` 関連ライブラリがなくエラーとなりました。発生原因がよくわかりませんが、ライブラリのインストールで解消しました。
```console
pip install django-pylibmc
画面動作確認時のエラー対処
check コマンドで問題を検出した後、画面操作し対処を行いました。
ImportError: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class
jango/core/handlers/wsgi.py", line 127, in __init__
[Wed Dec 29 19:07:36.997202 2021] [wsgi:error] [pid 22864:tid 140029485946624] [remote 66.249.68.93:62902] self.load_middleware()
[Wed Dec 29 19:07:36.997209 2021] [wsgi:error] [pid 22864:tid 140029485946624] [remote 66.249.68.93:62902] File "/var/www/python-venv/blog/.venv/lib/python3.6/site-packages/django/core/handlers/base.py", line 40, in load_middleware
[Wed Dec 29 19:07:36.997212 2021] [wsgi:error] [pid 22864:tid 140029485946624] [remote 66.249.68.93:62902] middleware = import_string(middleware_path)
[Wed Dec 29 19:07:36.997233 2021] [wsgi:error] [pid 22864:tid 140029485946624] [remote 66.249.68.93:62902] File "/var/www/python-venv/blog/.venv/lib/python3.6/site-packages/django/utils/module_loading.py", line 24, in import_string
[Wed Dec 29 19:07:36.997237 2021] [wsgi:error] [pid 22864:tid 140029485946624] [remote 66.249.68.93:62902] ) from err
[Wed Dec 29 19:07:36.997264 2021] [wsgi:error] [pid 22864:tid 140029485946624] [remote 66.249.68.93:62902] ImportError: Module "django.contrib.auth.middleware" does not define a "SessionAuthenticationMiddleware" attribute/class
Django 2.xから、SessionAuthenticationMiddleware
は削除されたようです。Middlewareから削除したところエラーが解消しました。以下の記事が参考になりました。
- python - Django - ImproperlyConfigured: Module “django.contrib.auth.middleware” - Stack Overflow
- Django 2.0 release notes | Django documentation | Django
get_template_sources() takes 2 positional arguments but 3 were given
django-amp-tools
を参考に作ったLoaderクラスでエラーが発生していて、参考元のソースでのIssueがありました。
get_template_sources() takes 2 positional arguments but 3 were given · Issue #13 · shtalinberg/django-amp-tools
Django2.xから動作しなくなったようで、パッチもリリースされていません。
GoogleのAMP自体の優遇がなくなったので、対応はせず、機能を削除しました。
AttributeError: ‘WSGIRequest’ object has no attribute ‘session
AttributeError: 'WSGIRequest' object has no attribute 'session
geoip2_extras.middleware.GeoIP2Middleware
で発生したエラーです。 Middlewareの順序指定の見直しで解消されそうですが、必須で使用したい機能ではなかったので、Middlewareの指定を外しました。
Your version of Django supports SameSite flag in the cookies mechanism. You should remove django-cookies-samesite from your project.
Your version of Django supports SameSite flag in the cookies mechanism. You should remove django-cookies-samesite from your project.
django-cookies-samesite
は使用ライブラリから削除すべきという警告です。 警告ですが、画面表示でエラーとなってい他ので、INSTALL_APPS から
django-cookies-samesite
を削除しました。 SameSite cokiesの設定については以下の記事が参考になりました。
- DjangoでSameSite属性を扱う方法 - ryu22eBlog
- python 3.x - Django - check cookies’s “SameSite” attribute - Stack Overflow
TypeError: render() got an unexpected keyword argument 'renderer'
ADMIN画面の操作中に以下のエラーが発生しました。
File "/var/www/python-venv/blog/.venv/lib/python3.6/site-packages/django/forms/boundfield.py", line 34, in __str__
return self.as_widget()
File "/var/www/python-venv/blog/.venv/lib/python3.6/site-packages/django/forms/boundfield.py", line 97, in as_widget
renderer=self.form.renderer,
TypeError: render() got an unexpected keyword argument 'renderer'
django.forms.widgets.Widget
のrender
メソッドのシグネチャが Django 2.1
から変更になったため発生するエラーです。アプリケーション独自で作成していたWidget のサブクラスの、render
メソッドを修正することで解消しました。以下、StackOverflowの記事が参考になりました。
JQuery - $ is not defined
ADMIN画面操作中に、JQuery - $ is not defined
が発生しました。
これは、Mezzainneが依存している JQuery のバージョンが上がったため発生しており、python3.6 manage.py collectstatic
を実行することで解消しました。
Upgrade後のライブラリ
Upgrade後のpip list
の結果を貼っておきます。
python3.6 -m pip list
Package Version
-------------------------- -----------
asgiref 3.4.1
backports.zoneinfo 0.2.1
beautifulsoup4 4.7.1
bleach 3.1.0
cachetools 3.1.0
certifi 2019.3.9
chardet 4.0.0
charset-normalizer 2.0.9
coreapi 2.3.3
coreschema 0.0.4
cssmin 0.2.0
Django 3.2.10
django-appconf 1.0.3
django-contrib-comments 2.1.0
django-critical 0.1.1
django-crontab 0.7.1
django-csp 3.7
django-csp-reports 1.6
django-extensions 2.1.6
django-filter 2.1.0
django-geoip2-extras 1.1.2
django-guess 0.0.1
django-health-check 3.12.1
django-htmlmin 0.11.0
django-oauth-toolkit 1.1.3
django-pylibmc 0.6.1
django-recaptcha 2.0.6
django-request 1.6.0
django-rest-swagger 2.2.0
django-robots 4.0
django-webpack-loader 0.6.0
djangorestframework 3.13.1
filebrowser-safe 1.0.0
future 0.17.1
geoip2 2.9.0
get 2019.4.13
google-api-python-client 1.7.8
google-auth 1.6.3
google-auth-httplib2 0.0.3
Google2Pandas 0.1.1
grappelli-safe 1.0.0
html5lib 1.0.1
httplib2 0.12.3
idna 2.8
importlib-resources 5.4.0
itypes 1.1.0
Jinja2 2.10.1
Markdown 3.1
MarkupSafe 1.1.1
maxminddb 2.0.2
mecab-python3 0.996.2
Mezzanine 5.0.0
mezzanine-api 0.7.1
mezzanine-pagedown 1.3
mezzanine-pubsubhubbub-pub 0.0.5
mock 2.0.0
numpy 1.16.3
oauth2client 4.1.3
oauthlib 3.0.1
openapi-codec 1.3.2
pandas 0.24.2
pbr 5.1.3
Pillow 8.4.0
pip 21.3.1
post 2019.4.13
psutil 5.7.2
psycopg2 2.8.2
public 2019.4.13
pyasn1 0.4.5
pyasn1-modules 0.2.5
Pygments 2.3.1
pylibmc 1.6.1
pymdown-extensions 6.0
python-dateutil 2.8.0
python-memcached 1.59
pytz 2019.1
pytz-deprecation-shim 0.1.0.post0
query-string 2019.4.13
request 2019.4.13
requests 2.26.0
requests-oauthlib 1.3.0
rsa 4.0
scikit-learn 0.20.3
scipy 1.2.1
setuptools 39.0.1
simplejson 3.16.0
six 1.12.0
soupsieve 1.9.1
sqlparse 0.4.2
typing_extensions 4.0.1
tzdata 2021.5
tzlocal 4.1
uritemplate 3.0.0
urllib3 1.24.2
webencodings 0.5.1
zipp 3.6.0
参考
以下、参考にした記事になります。
* Googleの「AMP優遇」がまもなく終了 - GIGAZINE
Django 1.x から Django 3.x へのアップデートになり、Mezzanine というか Django のプラグインでのエラーが大量に発生しました。
なかなかエラーを解消できず、2-3時間サイト停止させてしまいました。。
事前の検証はやっておいたほうが良いかなと思いました。
コメント