Opened 8 years ago
Last modified 7 years ago
#5544 review defect
Orphaned notifications
| Reported by: | ayleph | Owned by: | |
|---|---|---|---|
| Priority: | critical | Milestone: | |
| Component: | programming | Keywords: | notifications |
| Cc: | Parent Tickets: |
Description
My database contains a number of orphaned notifications that result in server errors with the following output.
File '/path/to/mediagoblin/mediagoblin/templates/mediagoblin/fragments/header_notifications.html', line 8 in top-level template code
{% set comment_object = comment_wrapper.comment() %}
UndefinedError: 'None' has no attribute 'comment'
For users that want notifications, this results in server errors every time they log in or try to navigate to any page while logged in, effectively locking them out of the instance.
Change History (3)
comment:1 by , 8 years ago
comment:2 by , 8 years ago
I can use the following band-aid to prevent this from throwing a server error. It still shows a notification count and the "mark all read" link, even though it might not show any notifications, but that's better than crashing. I'm going to apply this to my local instance while I continue to investigate. It might not be a bad idea to apply this patch to the codebase too, just as an extra layer of error checking.
--- a/mediagoblin/templates/mediagoblin/fragments/header_notifications.html
+++ b/mediagoblin/templates/mediagoblin/fragments/header_notifications.html
@@ -4,6 +4,7 @@
<h3>{% trans %}New comments{% endtrans %}</h3>
<ul>
{% for notification in notifications %}
+ {% if notification.obj() %}
{% set comment_wrapper = notification.obj() %}
{% set comment_object = comment_wrapper.comment() %}
{% set comment_author = comment_object.get_actor %}
@@ -35,6 +36,7 @@
</div>
</li>
+ {% endif %}
{% endfor %}
</ul>
<a href="{{ request.urlgen('mediagoblin.notifications.mark_all_comment_notifications_seen') }}?next={{

Here's a high level overview of my tables.
I have 1300 rows in
core__comment_links.idthat matches theobj_pkfromcore__generic_model_reference.idthat does not exist incore__generic_model_reference.I have 1428 rows in
core__generic_model_referencewithmodel_typeofcore__comment_links.obj_pkthat matches theidfromcore__comment_links, as above.obj_pkthat does not exist incore__comment_links.I have 45 rows in
core__notificationsthat reference one of the 219 rows incore__generic_model_referencewhich does not have a corresponding entry incore__comment_links.This leads me to believe that when comments are deleted, they are removed from the
core__comment_linkstable but not from thecore__generic_model_referenceandcore__notificationstables, resulting in orphaned notifications.(As for the 91 comments that don't exist in GMR, I haven't dug deep enough to determine what caused those, but my first guess would be those existed before we switched to the new comment model.)