{{{
Traceback:
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/core/handlers/base.py" in get_response
112. response = wrapped_callback(request,
*callback_args, **callback_kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/contrib/admin/options.py" in wrapper
465. return self.admin_site.admin_view(view)(*args,
**kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/views/decorators/cache.py" in _wrapped_view_func
52. response = view_func(request, *args, **kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/contrib/admin/sites.py" in inner
198. return view(request, *args, **kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/utils/decorators.py" in _wrapper
29. return bound_func(*args, **kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/utils/decorators.py" in _wrapped_view
99. response = view_func(request, *args, **kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/utils/decorators.py" in bound_func
25. return func(self, *args2, **kwargs2)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/db/transaction.py" in inner
371. return func(*args, **kwargs)
File "/home/johannes/formonauts/donation/.env/local/lib/python2.7/site-
packages/django/contrib/admin/options.py" in add_view
1164. self.save_model(request, new_object, form, False)
File "/home/johannes/formonauts/donation/server/django-
donut/donut/admin.py" in save_model
36. obj.save()
File "/home/johannes/formonauts/donation/server/django-
donut/nanny/models.py" in save
109. self.refresh_from_db()
File "/home/johannes/formonauts/donation/server/django-
donut/donut/basemodels.py" in refresh_from_db
80. related_val = getattr(rel_instance,
field.related_field.attname)
Exception Type: AttributeError at /admin/nanny/team/add/
Exception Value: 'NoneType' object has no attribute 'id'
}}}
here rel_instance is assigned:
https://github.com/django/django/blob/stable/1.8.x/django/db/models/base.py#L630
if it is None (foreignkey not set, as it is nullable in this model) the
getattr function will complain that it can not get 'id' from 'NoneType'
--
Ticket URL: <https://code.djangoproject.com/ticket/24418>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* severity: Normal => Release blocker
* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
Comment:
Reproduced with the attached test.
--
Ticket URL: <https://code.djangoproject.com/ticket/24418#comment:1>
* has_patch: 0 => 1
--
Ticket URL: <https://code.djangoproject.com/ticket/24418#comment:2>
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/24418#comment:3>
* status: new => closed
* resolution: => fixed
Comment:
In [changeset:"5cf96b49e43daea6d4a0ba1c80c45e90c74f4e47"]:
{{{
#!CommitTicketReference repository=""
revision="5cf96b49e43daea6d4a0ba1c80c45e90c74f4e47"
Fixed #24418 -- Prevented crash in refresh_from_db with null fk
Thanks Johannes Lerch for the report, Tim Graham for the test case,
and Simon Charette for the review.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24418#comment:4>
Comment (by Claude Paroz <claude@…>):
In [changeset:"b825ec38c1e16a271c69694562963eadbe0c6352"]:
{{{
#!CommitTicketReference repository=""
revision="b825ec38c1e16a271c69694562963eadbe0c6352"
[1.8.x] Fixed #24418 -- Prevented crash in refresh_from_db with null fk
Thanks Johannes Lerch for the report, Tim Graham for the test case,
and Simon Charette for the review.
Backport of 5cf96b49e4 from master.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/24418#comment:5>
Old description:
New description:
If i try to call refresh_from_db on a model instance that has a foreignkey
set to null, i get an error:
(stacktrace was removed after ticket was resolved)
here rel_instance is assigned:
https://github.com/django/django/blob/stable/1.8.x/django/db/models/base.py#L630
if it is None (foreignkey not set, as it is nullable in this model) the
getattr function will complain that it can not get 'id' from 'NoneType'
--
--
Ticket URL: <https://code.djangoproject.com/ticket/24418#comment:6>