{{{
# Next, look for a many-to-one relationship to Site.
if object_domain is None:
for field in obj._meta.fields:
if field.rel and field.rel.to is Site:
try:
object_domain = getattr(obj, field.name).domain
except Site.DoesNotExist:
pass
}}}
Either explicitly checking that the result of the `getattr` call is not
`None` or catching a `AttributeError` will fix this.
--
Ticket URL: <https://code.djangoproject.com/ticket/26085>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* needs_better_patch: => 0
* component: Uncategorized => contrib.contenttypes
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0
* type: Uncategorized => Bug
* stage: Unreviewed => Accepted
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:1>
Comment (by jibaku):
Created a PR. Feedback needed, it's my first PR to Django.
https://github.com/django/django/pull/5986
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:2>
* owner: nobody => jibaku
* status: new => assigned
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:3>
* needs_better_patch: 0 => 1
* has_patch: 0 => 1
Comment:
[https://github.com/django/django/pull/5986 PR] (test failures)
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:4>
* cc: daniponi (added)
* needs_better_patch: 1 => 0
Comment:
Created a PR to fix the test problem as suggested by claudep.
[https://github.com/django/django/pull/6427]
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:5>
* needs_better_patch: 0 => 1
Comment:
Left some comments for improvement on the updated PR.
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:6>
* needs_better_patch: 1 => 0
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:7>
Comment (by jaap3):
Sorry, I'm of the opinion that raising a 404 is the wrong solution. All
other exceptions that are caught (IndexError, Site.DoesNotExist) are
silently ignored, I think the same should be done for a None value.
The reason I stumbled upon this issue in the first place is that in my use
case objects with no explicit site relation are available on all sites. So
raising a 404 would be not be much of an improvement over raising a 500
;-).
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:8>
* needs_better_patch: 0 => 1
Comment:
Makes sense.
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:9>
* needs_better_patch: 1 => 0
Comment:
Changed the PR according to jaap3's suggestion
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:10>
* needs_better_patch: 0 => 1
Comment:
Left a few cosmetic comments and tests aren't passing on databases other
than SQLite.
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:11>
* needs_better_patch: 1 => 0
* stage: Accepted => Ready for checkin
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:12>
* status: assigned => closed
* resolution: => fixed
Comment:
In [changeset:"d29d11b026e8acea4778dd596aaf82d55b11f44d" d29d11b]:
{{{
#!CommitTicketReference repository=""
revision="d29d11b026e8acea4778dd596aaf82d55b11f44d"
Fixed #26085 -- Fixed contenttypes shortcut() view crash with a null fk to
Site.
Thanks Fabien Schwob for the initial patch.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:13>
Comment (by Tim Graham <timograham@…>):
In [changeset:"2a9bcb503f2aa1b7462174cf95852a2aafbe90ec" 2a9bcb5]:
{{{
#!CommitTicketReference repository=""
revision="2a9bcb503f2aa1b7462174cf95852a2aafbe90ec"
Refs #26085, #11505 -- Cleared Site cache in contenttypes_tests.
}}}
--
Ticket URL: <https://code.djangoproject.com/ticket/26085#comment:14>