Traceback (most recent call last):
File "/code/logger/test_urls.py", line 52, in test_detail_page_not_authenticated
response = client.get(reverse('logger:detail'))
File "/usr/local/lib/python3.8/site-packages/django/test/client.py", line 732, in get
response = super().get(path, data=data, secure=secure, extra)
File "/usr/local/lib/python3.8/site-packages/django/test/client.py", line 393, in get
return self.generic('GET', path, secure=secure, {
File "/usr/local/lib/python3.8/site-packages/django/test/client.py", line 470, in generic
return self.request(r)
File "/usr/local/lib/python3.8/site-packages/django/test/client.py", line 709, in request
self.check_exception(response)
File "/usr/local/lib/python3.8/site-packages/django/test/client.py", line 571, in check_exception
raise exc_value
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/exception.py", line 47, in inner
response = get_response(request)
File "/usr/local/lib/python3.8/site-packages/django/core/handlers/base.py", line 179, in _get_response
response = wrapped_callback(request, *callback_args, *callback_kwargs)
File "/code/logger/views.py", line 53, in detail
history = UserBossHistory.objects.filter(user_id=user)
File "/usr/local/lib/python3.8/site-packages/django/db/models/manager.py", line 85, in manager_method
return getattr(self.get_queryset(), name)(args, kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 942, in filter
return self._filter_or_exclude(False, *args, kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 962, in _filter_or_exclude
clone._filter_or_exclude_inplace(negate, *args, *kwargs)
File "/usr/local/lib/python3.8/site-packages/django/db/models/query.py", line 969, in _filter_or_exclude_inplace
self._query.add_q(Q(args, kwargs))
File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1358, in addq
clause, = self._add_q(q_object, self.used_aliases)
File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1377, in _add_q
child_clause, needed_inner = self.build_filter(
File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1292, in build_filter
self.check_related_objects(join_info.final_field, value, join_info.opts)
File "/usr/local/lib/python3.8/site-packages/django/db/models/sql/query.py", line 1121, in check_related_objects
for v in value:
File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 241, in inner
return func(self._wrapped, *args)
TypeError: 'AnonymousUser' object is not iterable
ミドルウェアで認証確認を行っているが,detailページについてのみテストに失敗する. 実際に画面遷移を見ると非ログイン時はログインページに問題なくリダイレクトできているが, 内部的にuserが呼ばれる処理が走ってしまっている? エラーを起こしている直接の箇所は
の可能性がある. (実際の画面表示ではリダイレクトしておりここが呼ばれていないので推測)
一旦,detailのview内で別途auchenticatedを確認することで回避. ミドルウェアの設定もしくはテストコードの見直しが必要.