Ask Your Question
1

Inconsistent db after deleting a user?

asked 2011-12-12 16:24:01 -0500

piskvorky gravatar image piskvorky
350 9 4 19

updated 2012-12-21 19:42:19 -0500

Evgeny gravatar image Evgeny flag of Chile
11009 50 84 182
http://askbot.org/

Viewing a particular user's profile leads to internal server error, with the following traceback:

File "/home/www-data/askbot-devel/askbot/skins/default/templates/user_profile/user_stats.html" in top-level template code
2. {% import "macros.html" as macros %}
File "/home/www-data/askbot-devel/askbot/skins/default/templates/user_profile/user.html" in top-level template code
1. {% extends "one_column_body.html" %}
File "/home/www-data/askbot-devel/askbot/skins/common/templates/one_column_body.html" in top-level template code
1. {% extends "base.html" %}
File "/home/www-data/askbot-devel/askbot/skins/default/templates/base.html" in top-level template code
23.             {% block body %}
File "/home/www-data/askbot-devel/askbot/skins/common/templates/one_column_body.html" in block "body"
5.     {% block content%}
File "/home/www-data/askbot-devel/askbot/skins/default/templates/user_profile/user.html" in block "content"
17.         {% block usercontent %}
File "/home/www-data/askbot-devel/askbot/skins/default/templates/user_profile/user_stats.html" in block "usercontent"
120.                                             title="{{ award.content_object.get_snippet()|collapse }}"

Exception Type: UndefinedError at /qa/users/1/radim/
Exception Value: 'None' has no attribute 'get_snippet'

Other users' profiles work ok, no problem.

I was banging my head against the wall for a while. Then I remember I had been deleting users (test accounts etc), through the admin interface.

My suspicion is that user 1/radim got a badge for one of the questions/answers for a user that was deleted, and now that the user disappeared, some queries fail with the above traceback

Is that possible? Can you think of any other cause for this error? How to fix it now, and what is the recommended way to delete users?

delete close flag offensive retag edit

Comments

I've seen similar (exception None has no attribute get_snippet) issues after clearing the 'awards' table through the admin site and then opening up user profile page. But i can't seem to reproduce it again... just fyi.

drpoovilleorg ( 2011-12-14 03:54:40 -0500 )edit

Added a check {% if award.content_object ... %} around that spot, this should fix the issue, but I don't have a test case.

Evgeny ( 2012-12-21 19:40:22 -0500 )edit

1 Answer

Sort by ยป oldest newest most voted
1

answered 2011-12-14 07:01:03 -0500

Evgeny gravatar image Evgeny flag of Chile
11009 50 84 182
http://askbot.org/

updated 2012-12-21 19:41:36 -0500

edit: fixed in the repo, will be available in 0.7.48.

Filed an issue http://bugs.askbot.org/issues/155 - we might not be able to allow deleting users from the admin interface, instead we might try to block that possibility and implement the user deletion in some other way.

The main problem is that in django when you delete content - all related records - will be automatically deleted as well. This is not always what you want.

Apparently in the automatic deletion of related content there is a glitch - when relation is generic - that is it is recorded via use of numeric id's instead of foreign keys - those relations are not cleaned up. That explains the error that you found.

For now - don't use admin interface to delete records in askbot, but for some edits admin is fine. We should probably just forbid deletion of records via admin until we have cleanup procedures for the generic relations.

link publish delete flag offensive edit

Comments

(can't access that url.) Anyhow I'm thinking how to fix the situation now -- is deleting extra records from awards (or other tables?) going to help?

piskvorky ( 2011-12-15 18:15:05 -0500 )edit

Looks like autolink url regex needs to be fixed, for this filed issue http://bugs.askbot.org/issues/156 :).

Evgeny ( 2011-12-15 18:20:49 -0500 )edit

It is possible to add a post_delete or pre_delete signal handler for the User model that will delete generic relations to the removed item - whichever is more appropriate here.

Evgeny ( 2011-12-15 18:28:38 -0500 )edit

Your answer

Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Reliable Askbot Hosting

Create your Q&A site at askbot.com. Managed Askbot hosting at just $15/mo. Dedicated hosting, support contracts, consulting services.

create your Q&A site
30 days free trial

Question tools

Follow
1 follower

subscribe to rss feed

Stats

Asked: 2011-12-12 16:24:01 -0500

Seen: 104 times

Last updated: Dec 21 '12