Duplicate entry error
jsimonis - May 30, 2007 - 07:49
| Project: | Organic groups |
| Version: | 5.x-3.0 |
| Component: | og.module |
| Category: | bug report |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | closed |
Description
Every time I add a new group, I get this error (the number after " Duplicate entry ' " increments):
user warning: Duplicate entry '2-0-og_public' for key 1 query: INSERT INTO node_access (nid, realm, gid, grant_view, grant_update, grant_delete) VALUES (2, 'og_public', 0, 1, 0, 0) in /home/gweekly/public_html/includes/database.mysql.inc on line 172.
I'm extremely new to OG, so maybe I'm doing something wrong. However, I checked all my settings and I did everything the way the install said.
Thanks in advance!

#1
And because of this error, the groups are not private -- I'm logged in as a person who is only a member of one group. But I can see all of the groups and their content.
#2
Never mind about the second item... it's not viewable by others.
But I am still getting that error. It shows up anytime I add a group, edit a group, etc.
#3
Same error here.
#4
Have same error
#5
I just upgraded from 2.2 to 3.0 and now it submits og_public twice to the node_access_write_grants function, which results in the duplicate entry error message. No matter if a new group node is being created, or and existing one is edited.
Works fine for non group nodes
#6
Yea, with mine it doesn't matter if it is a new group node, or a current one being edited. I get the duplicate error no matter what.
But I haven't used a previous version of OG - this is a brand new install.
#7
OK, I found out whats going on. In the og.module node_access_records hook (og_node_access_records) it adds the ob_public grant twice.
This can be fixed easily by adding an if statement like so (look for jamgold)
function og_node_access_records($node) {
// don't write records if og access control is disabled or the node type is omitted or node is a group
if (og_is_omitted_type($node->type) || !variable_get('og_enabled', FALSE)) {
return;
}
if (og_is_group_type($node->type)) {
// this grant allows group admins to manage stuff
$grants[] = array('realm' => 'og_subscriber', 'gid' => $node->nid, 'grant_view' => 1, 'grant_update' => 1, 'grant_delete' => 1);
// this one lets everyone see group homepage. see 'private groups' issue if you don't want this. we need help.
// jamgold: only add if not already set, or it will be added again bellow
if(!$node->og_public)
$grants[] = array('realm' => 'og_public', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
}
elseif (is_array($node->og_groups)) {
// applies to non group nodes
foreach ($node->og_groups as $gid) {
// we write a broad grant here but og_node_grants() only issues it selectively.
$grants[] = array('realm' => 'og_subscriber', 'gid' => $gid, 'grant_view' => 1, 'grant_update' => 1, 'grant_delete' => 1);
}
}
if ($node->og_public) {
$grants[] = array('realm' => 'og_public', 'gid' => 0, 'grant_view' => 1, 'grant_update' => 0, 'grant_delete' => 0);
}
return $grants;
}
Since upgrading to 3.0 on a live site messed up my day, I won't have time roll and submit a patch. Maybe later.
#8
Here is the patch against 5.x-3.0.
#9
Thanks!
I had the feeling it was something like that, since everything seems to work fine - it just gives the duplicate error.
#10
Thanks, jhm. That fixed it for me, too.
For what it's worth, when I deleted the groups I created that triggered the error, I noticed that the corresponding records in node_access were not also deleted. (These are the records in node_access that had the same nid as the groups I deleted.) Ummm ... should these also be cleared out?
Please advise ... if this looks like it might be a problem, let me know, and I'll gather enough data to reproduce it and file a bug report.
#11
node_access is a table belonging to the base node.module. Why don't you enable the devel module query log and see which queries it fires when deleting a group? It sure is not a good idea to have nid zombies in the node_access table, but then again the nid sequence is always increased and old nids are never reused, so I can't see an immediate problem here. I would try to debug that some more, however, before filing a bug.
#12
Thanks for the advice ... I'll poke through this some more, and see if it looks like a real problem or not.
#13
Seeing this problem too on a clean, fully up-to-date install of D5 and friends. I created a couple OGs without access control enabled and got no errors. Turning on access control and edited one of the existing groups (i.e. resaved) and got the error.
The patch fixes the symptoms, but I wonder if it's really fixing the problem.
#14
fixed. thanks.
#15