咳咳,终于考完试了,因为马上 DDL 了所以先把自己手上的版本拿来部署到生产服务器上去。
但是在部署完成后,运行前端页面,提示如下错误:
2021-06-04 07:57:19,187 [ERROR] django.request:228 log_response Internal Server Error: /
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/exception.py", line 34, in inner
response = get_response(request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 115, in _get_response
response = self.process_exception_by_middleware(e, request)
File "/usr/local/lib/python3.6/dist-packages/django/core/handlers/base.py", line 113, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/var/seafile/source/seahub/seahub/auth/decorators.py", line 27, in _wrapped_view
return view_func(request, *args, **kwargs)
File "/var/seafile/source/seahub/seahub/views/__init__.py", line 1214, in react_fake_view
'enable_ocm': ENABLE_OCM,
File "/usr/local/lib/python3.6/dist-packages/django/shortcuts.py", line 36, in render
content = loader.render_to_string(template_name, context, request, using=using)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader.py", line 62, in render_to_string
return template.render(context, request)
File "/usr/local/lib/python3.6/dist-packages/django/template/backends/django.py", line 61, in render
return self.template.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 171, in render
return self._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py", line 150, in render
return compiled_parent._render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 163, in _render
return self.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/loader_tags.py", line 62, in render
result = block.nodelist.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 937, in render
bit = node.render_annotated(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/base.py", line 904, in render_annotated
return self.render(context)
File "/usr/local/lib/python3.6/dist-packages/django/template/library.py", line 192, in render
output = self.func(*resolved_args, **resolved_kwargs)
File "/usr/local/lib/python3.6/dist-packages/webpack_loader/templatetags/webpack_loader.py", line 12, in render_bundle
tags = utils.get_as_tags(bundle_name, extension=extension, config=config, attrs=attrs)
File "/usr/local/lib/python3.6/dist-packages/webpack_loader/utils.py", line 62, in get_as_tags
bundle = _get_bundle(bundle_name, extension, config)
File "/usr/local/lib/python3.6/dist-packages/webpack_loader/utils.py", line 40, in _get_bundle
bundle = get_loader(config).get_bundle(bundle_name)
File "/usr/local/lib/python3.6/dist-packages/webpack_loader/loader.py", line 90, in get_bundle
asset = assets['assets'][chunk]
KeyError: 'assets'
很奇怪,明明在开发环境没问题,但是到了生产环境就爆炸了。。。
很离谱,这东西根本就不是我代码里的。出现错误以后,我还傻乎乎地在 Git 提交记录里找错误。。。
我回想起来,当时我队友也遇到过一次这个问题,当时我们没找到解决方法,因为我自己电脑上的是完全正常的。于是我把自己的 docker 容器直接传给队友一份,让他直接用我的环境,这事也就解决了。但是治标不治本,我们仍然没有找到问题的根源。
不过根据上述情况,我一开始以为是我不小心在 gitignore 里面 exclude 了某些重要的东西,这可以解释为什么我的开发环境一直正常,但是生产环境却错误。不过经过排查,并没有什么东西被 exclude。
然后我做了一个违背祖宗的决定,直接到出错的代码行去找问题。根据提示,打开 /usr/local/lib/python3.6/dist-packages/webpack_loader/loader.py
文件,我找到了出错的代码行:
asset = assets['assets'][chunk]
既然是报 keyError,那我们来看看你的 assets 里面到底有什么吧:
这个图是我把输出结果弄到一个美化程序里得到的结果。我感到很奇怪,这里哪来的 assets
key 啊?感觉似乎确实有些问题。
但是我想了想,既然开发环境没问题,那只有两种情况:
我打开了开发环境对应的 /usr/local/lib/python3.6/dist-packages/webpack_loader/loader.py
文件,我发现。。。果然是第二种。。。
使用 pip list
命令,可以清楚的看到,django-webpack_loader
的版本从 0.7.0 变成了 1.0.0。。。。。差点让我破防
于是,愉快的在安装指南博客里加入了 django-webpack_loader == 0.7.0
的版本限制,就好了。坑爹啊。。。。。。
不过感觉以后找时间可以把这些组件的版本更新一下下。