Mezzanine 4.1 から、4.2update したところ、
plugin 周辺で以下エラーが高確率で出力さていました。
Django1.9 では、render_to_response存在していた引数が、
Django1.10render_to_response では引数から削除されていたことが原因でした。
対処方法を備忘として残します。※1※2

File "/usr/local/lib/python2.7/site-packages/request/admin.py" in overview
 81.         }, context_instance=RequestContext(request))
Exception Type: TypeError at xxx...
Exception Value: render_to_response() got an unexpected keyword argument 'context_instance'
※1 django-request 1.4でのエラー抜粋になります。
※2 xxx... は、発生箇所により異なります。


前提

以下の環境で実行しています。
* OS
CentOS release 6.7 (Final)

  • Python Version
    Python 2.7.8

  • Package (必要そうなものだけ抜粋)
    Django (1.10.0)
    Mezzanine (4.2.0)


原因

render_to_response()パラメータcontext_instancedjango 1.10削除されていますが、
そんなことは知らずに、context_instance指定しているため、エラー発生が発生しています。

Django1.9 shortcut functions では、

render_to_response()

render_to_response(template_name, context=None, context_instance=_context_instance_undefined, content_type=None, status=None, dirs=_dirs_undefined, using=None)

context_instance存在しますが、

Django1.10 shortcut functions では、

render_to_response()

render_to_response(template_name, context=None, content_type=None, status=None, using=None)

context_instance削除されています。
dirs削除されてます。


対処方法

Django 1.8 release notes に、記載がありますが、
context_instance指定して、render_to_response()呼び出している場合は、render()変更すれば良いようです。

django-requestついては、github最新版のソースコード既に対応済だったので、対応部分をコピペしました。
以下、対応箇所の抜粋になります。

  • /usr/local/lib/python2.7/site-packages/request/admin.py

 5 #from django.shortcuts import render_to_response
 6 from django.shortcuts import render       

73     def overview(self, request):
74         qs = Request.objects.this_month()
75         for plugin in plugins.plugins:
76             plugin.qs = qs
77         # 元の記述はコメントアウト
78         #return render_to_response('admin/request/request/overview.html', {
79         #    'title': _('Request overview'),
80         #    'plugins': plugins.plugins,
81         #}, context_instance=RequestContext(request))
82         
83         return render(
84             request,
85             'admin/request/request/overview.html',
86             {
87                 'title': _('Request overview'),
88                 'plugins': plugins.plugins,
89             }                            
90         )

まあ、こっちがdjangoversion ゴリゴリあげているのがいけないんでしょうけど、
いつ、PACKAGE INDEX登録されるのだろう。。


追記 (2017/07/14)

最新version の django-request をインストールすると、
上記の事象は解消されます。
django-request 1.5.1 : Python Package Index

以上です。


参考サイト

コメント