SimpleLazyObjectというエラーメモ


こんなエラーが出た。

TypeError at /plan/
int() argument must be a string, a bytes-like object or a number, not 'SimpleLazyObject'
Request Method: GET
Request URL: http://djangoapps:8000/plan
Django Version: 1.8.2
Exception Type: TypeError
Exception Value:
int() argument must be a string, a bytes-like object or a number, not 'SimpleLazyObject'
Exception Location: /home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/fields/__init__.py in get_prep_value, line 985
Python Executable: /home/ec2-user/.pyenv/versions/3.4.3/bin/python
Python Version: 3.4.3

Tracebackはこんな感じ。

File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/core/handlers/base.py" in get_response
132. response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/views/generic/base.py" in view
71. return self.dispatch(request, *args, **kwargs)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/views/generic/base.py" in dispatch
89. return handler(request, *args, **kwargs)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/views/generic/base.py" in get
158. context = self.get_context_data(**kwargs)
File "/home/ec2-user/djangoapps/apps/djangoapps/views.py" in get_context_data
36. plan, created = Plan.objects.get_or_create(user=self.request.user)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/manager.py" in manager_method
127. return getattr(self.get_queryset(), name)(*args, **kwargs)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/query.py" in get_or_create
405. return self.get(**lookup), False
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/query.py" in get
325. clone = self.filter(*args, **kwargs)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/query.py" in filter
679. return self._filter_or_exclude(False, *args, **kwargs)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/query.py" in _filter_or_exclude
697. clone.query.add_q(Q(*args, **kwargs))
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/sql/query.py" in add_q
1304. clause, require_inner = self._add_q(where_part, self.used_aliases)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/sql/query.py" in _add_q
1332. allow_joins=allow_joins, split_subq=split_subq,
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/sql/query.py" in build_filter
1194. lookups, value)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/fields/related.py" in get_lookup_constraint
1740. lookup_class(target.get_col(alias, source), val), AND)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/lookups.py" in __init__
96. self.rhs = self.get_prep_lookup()
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/lookups.py" in get_prep_lookup
134. return self.lhs.output_field.get_prep_lookup(self.lookup_name, self.rhs)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/fields/__init__.py" in get_prep_lookup
727. return self.get_prep_value(value)
File "/home/ec2-user/.pyenv/versions/3.4.3/lib/python3.4/site-packages/django/db/models/fields/__init__.py" in get_prep_value
985. return int(value)

Exception Type: TypeError at /plan/
Exception Value: int() argument must be a string, a bytes-like object or a number, not 'SimpleLazyObject'

ログインしてなかっただけだった。

/admin
にアクセスしてログインしたら解消。

結構単純なミスですが、複数のブラウザを立ち上げていたり、複数のDjangoを立ち上げていたりすると、意外と陥るワナかなと思ったのでメモ。

初歩的なミスって気づかないことも多いですし、簡単なことって誰も書かないので。