First time here? Check out the FAQ!
3

IntegrityError when updating user

Hello! I want to integrate askbot to my django project. When I'm trying to update user information using admin interface, i'm getting this exception:

update or delete on table "auth_user_groups" 
violates foreign key constraint "authusergroups_ptr_id_refs_id_7859c44e" 
on table "askbot_groupmembership"

What are the reasons this can happen?

ib-soft's avatar
31
ib-soft
asked 2013-01-16 22:58:59 -0500, updated 2013-01-18 10:53:52 -0500
edit flag offensive 0 remove flag close merge delete

Comments

Do you have the same issue on askbot alone, without integration? What is the version of the database and Django?

Evgeny's avatar Evgeny (2013-01-18 14:32:31 -0500) edit

Yes. I deployed askbot as standalone app and still have this problem. Django 1.3.1 and Postgres 9.1.7. I suppose it connected with many to many relation between "auth_user" and "auth_group" (table auth_user_groups). When I deleted all records from table "askbot_groupmembership" user information updated without any exceptions.

ib-soft's avatar ib-soft (2013-01-21 00:14:55 -0500) edit

Thanks for the info. Maybe this is related to the postgres version, we'll test on that.

Evgeny's avatar Evgeny (2013-01-21 11:02:14 -0500) edit

Tested postgres 8.3 - same problem.

ib-soft's avatar ib-soft (2013-01-21 21:20:12 -0500) edit

9.1.8 same problem

bluebyte's avatar bluebyte (2013-03-10 14:34:28 -0500) edit
add a comment see more comments

2 Answers

1

I have exactly the same issue. I couldn't resolve the problem but did some diagnosis, so I wanted to share it with you. 1. The first user which is created using the django command line doesn't raise this issue. 2. The problem seems to come from the presence of the field "authusergroups_ptr_id" in the table "askbot_groupmembership". When a new user is created using the askbot interface, new groups are created and the "askbot_groupmembership" is populated with pointers to these groups. If you delete these pointers (entries) from the "askbot_groupmembership", then the save action works just fine.

I think, the reason why #1 works fine is that no groups and groupmemberships are created when the user is created with the manage.py commandline.

So, I think we should look at why these membership keys raise a problem. This seems to be happening in askbot/models/__init__.py during the creation of a new user but I couldn't figure out what the problem is.

Erdem's avatar
11
Erdem
answered 2013-01-24 23:29:02 -0500
edit flag offensive 0 remove flag delete link

Comments

Thanks for the information;) I just came to the same conclusion and I'm going to continue the investigation.

ib-soft's avatar ib-soft (2013-01-27 23:10:43 -0500) edit

I also have the same problem, on Django 1.4.3 and Postgres 9.1. Askbot installed standalone from scratch, I have git cloned yesterday from github. Has it been solved? Does a workaround exist? Thanks.

apalazon's avatar apalazon (2013-02-15 02:51:15 -0500) edit

I have the same. When register new user then created two new group in table "auth_group": _personal_(N) and _personal_(N+1). Why created new group?

wowas's avatar wowas (2013-05-16 02:38:53 -0500) edit

Yes we have the bug in the admin user. We will fix this at some point. Regarding that _personal_(N) group - the N is user id and is important for the groups feature. Basically to allow sharing certain content with individuals and to allow non-group members to ask questions to some group. This does not have a lot of use yet, but don't delete those groups.

Evgeny's avatar Evgeny (2013-05-16 04:01:12 -0500) edit

The bug may be actually in the django admin and may be due to the fact that we have a one-to-one relation between the bridge relation (user-group - the group membership), where the additional relation has level of the membership and django chokes on that. (take a look at askbot.models.user.GroupMembership). The solution may be to patch the auth_user_groups table so that it directly has the level field or invent independent concept of "askbot group membership" and keep it in sync with the auth_user_groups.

Evgeny's avatar Evgeny (2013-05-16 04:11:38 -0500) edit
add a comment see more comments
0

This must be caused by the post_save signal on the User object. Have a look at askbot/models/__init__.py.

It's possible that your sequence in the database is incorrect. If the current value of the sequence is less than some existing primary key, you might eventually get to the point where there will be violation of the primary key constraint.

Evgeny's avatar
13.2k
Evgeny
answered 2013-01-18 14:22:32 -0500
edit flag offensive 0 remove flag delete link

Comments

There are no problems with primary key. Constraint trigged on foreign key. (Look my comment higher)

ib-soft's avatar ib-soft (2013-01-21 00:26:10 -0500) edit
add a comment see more comments