Users are unable to unsubscribe from groups. Upon completing the un-subscription process it is as if nothing had ever happened. They are still listed as a member, and no error was thrown. On a plus side, user's are able to subscribe to groups.

I'm also tried removing members as the groups administrator and I've been unable to do that as well.

If I try to block active members of a group I get the exception

Exception: Group membership for entity user with ID 646 for group ID 34 (Reparations) already exists. in og_membership_create() (line 957 of C:\xampp\htdocs\531573_nachosyllabus\sites\all\modules\og\og.module).

I'm not sure if there is another way to remove group members and I'm just missing it, but everything I've tried has not worked.

#11 clean-db.sql_.gz127.43 KBcartagena
#9 dbDUMP.sql_.gz647.86 KBcartagena
Members fund testing for the Drupal project. Drupal Association Learn more


amitaibu’s picture

Can you attach a db dump?

bryancasler’s picture

I would be happy to, but this is for a live site. So, we would have to talk via email and you would need to sign a confidentiality agreement. Would that work for you?

amitaibu’s picture

> Would that work for you?

Nope :)

bryancasler’s picture

Well, I'll need this worked out by late next week:) For the rest of this week however, I'm squashing other bugs. If next week comes and I'm still running into this problem I'll probably try to find a way to hire you for a couple hours to troubleshoot. Would that work better for you?

cartagena’s picture

animelion and Amitaibu--
I ran into this same error and know that it is caused because I have the groups_audience field on the user edit page set to one for maximum number of values users can enter for this field. Although the error message says that the person already belongs to the current group, it is really that the one allowed value is already in the database. I've experimented with all the options, looking at the database between every change to see exactly what it's doing (because I don't know php I don't look at the code). When someone who is already in a group subscribes to another group, they do not immediately see the "unsubscribe" message. They continue to see "request group membership." When the group leader goes to the group tab to approve them, they are on the list as pending but no matter what action the leader takes, the role stays pending and this exception is thrown. The only way to fix it is to go into the database and change the field from pending to active. (which does allow then for a person to belong to more than one group) or to delete them. Otherwise they stay as pending and the group leader can't get rid of them.

I want to limit group membership to one group so I'm going to leave it this way and give instructions that the limit is one group and to join a different group one must unsubscribe from the first group.

I have this in a localhost dummy site so if a database dump would still be helpful I can provide it, Amitaibu. Thanks again for all your work!

amitaibu’s picture

Yes please attach the DB, with all unrelated modules/ configuration disabled.

Leeteq’s picture


bryancasler’s picture

Quick side question, I'm looking for a quick solution to this problem since I'm only working with about 100 subscriptions. In the DB is there a way to manually delete all the subscriptions. My plan is then to go and manually add all those users back. Is this possible as a interim workaround for sites with few subscriptions?

cartagena’s picture

647.86 KB

Here is the DB--I hope I got all the extraneous stuff stripped out. If you go into the Fulana1 Group and try to update the status of member fulana58 you'll get the error message. Thanks so much. I'll be happy to provide anything else I can, I am grateful for your expertise!

amitaibu’s picture

@cartagena ,
Thank you but the DB is still a mess. Please disable anything that's not related (date, redircet and other stuff I don't even have on my installation). If panels isn't needed, then please remove it.

After that, please let me the know the exact node I need to enter, with what member, and which member to remove. Like this I don't have to spend time in just setting up the DB -- thanks.

cartagena’s picture

127.43 KB

I'm sorry--I just keep learning. I did a clean install and only enabled og required modules. I created three users (UID 3, UID 4 and UID 5) and two groups (GID 2 and GID 3). I limited the groups_audience field to one value allowed. There are no other nodes as there is no other content.

UID 3 created group 2 and UID 4 joined it, all well and good.
UID 5 created group 3 and UID 4 joined it as well. But this time instead of the "subscribe" link changing to "unsubscribe" it stayed as "request group membership"

When group manager UID 5 went to approve UID 4, the error was generated. UID 4 is still listed as pending and state is 2 in DB.

I hope this is OK--next time I''ll know it's easier to start from scratch than to go backwards and delete...

amitaibu’s picture

Title: Users can not unsubscribe from their groups » Can't use og_group() when group-audience field cardinality is set to 1
Status: Active » Needs work

Better title.

> I limited the groups_audience field to one value allowed

That was an important information. The db you did was great (minor, next time set the users passwords to 1234 for easier access).

Before pushing it to main -dev, I've created a new branch git clone --branch 1203466, so you can already test the code, while I write tests.

amitaibu’s picture

fyi, tests don't pass yet.

bryancasler’s picture

Amitaibu, I should be able to test your work in 3 to 4 days. Thank's so much for working on this. If I can test sooner I will.

cartagena’s picture

Glad it was helpful, Amitaibu. You work fast!
I tested patch 1203466--here's what I got: when my user tried to join a second group the group type continued to remain "request group membership" rather than changing to "unsubscribe."

However, when the group manager went in to change the status from pending to active, the error was gone and it changed to active! When the user refreshed the page after the manager made the change, the group type field changed to "unsubscribe."

Is the purpose of limiting the groups audience field (rather than leaving it at unlimited) to keep a piece of group content associated with only a certain number of groups rather than allowing a user membership in only a certain number of groups? My goal is the latter, allowing the user to belong to only one group. But if the field isn't made for that purpose we'll simply ask our users to not join more than one group and it won't be a big deal if they go ahead and do it anyway.

Thanks again, I appreciate your patience!

bryancasler’s picture

I figured out what caused this scenario in the first place.

In my blog I have the group_audience field. I only want blogs to be posted to one group, so I changed its allowed values from unlimited to 1. This in turn changed the group_audience field that is on the user profile to be limited to 1 and this is what ultimately caused the problem.

Switching the group_audience field's value back to unlimited did solve some of the issues, but not all of them.

amitaibu’s picture

> Is the purpose of limiting the groups audience field (rather than leaving it at unlimited) to keep a piece of group content associated with only a certain number of groups rather than allowing a user membership in only a certain number of groups?

The formatter (i.e. the part of the code that shows the subscribe/ unsubscribe links) doesn't talk into account the widget's settings. It would be a nice feature, but I odn't really consider it a bug (the error message you got, before the fix was a bug).

amitaibu’s picture

Merged fix with -dev. If still happens, please re-open.

cartagena’s picture

OK, thanks so much!

bryancasler’s picture

This seems to be mostly resolved mostly. I'm still having the error popup when trying to remove some users, but I haven't found and rhyme or reason to its occurrence. If I do, I will follow up here.

spacereactor’s picture

Using the 7.x-1.x-dev 2011-Jul-08, previous version OG R3

When create new group node, i got this and the node isn't save.

Exception: Group membership for entity node with ID 881 for group ID 1 (newgroup) already exists. in og_membership_create() (line 965 of /var/www/

Update: og R3 at admin/config/group/group-membership there is no default so i create a group-membership call "team member" and after i install 7.x-1.x-dev, now i have "default" and "team member", i try to delete the "team member" doesn't solve the problem to create new node.

jungie71’s picture

So the problem is solved?
I just installed july 21 dev version... and Users still can't unsubscribe out of a group.
Is anyone having same problem? haven anyone solved this problem?\
If guild audience is 1 then unsubscribe problem still seems to kick in

Can anyone help me on this?

cartagena’s picture

It works well for me (I am still using the Jul 7 version). But here's what I discovered in my testing--which I keep playing with even though my groups are now live. If I create a group and add members and then delete the group via the admin find content page, records are left in the database (in the fields and og tables) for groups that no longer exist--even after clearing cache. Then when a member of that deleted group joins or unsubscribes from another group there are problems. If I manually delete the left over records from the database it's fine. So I have learned to unsubscribe all members through og before deleting a group and then there is no problem. And on my live site I didn't give anyone the ability to delete groups so all is fine there.

This is a really great module and even without knowing php I've been able to do so much with it. I will say I made sure to start slow on the live site and that helped, too--making it live and letting people find it slowly and start with a few groups so I could watch how it all works and keep tweeking. In a week or two we'll alert the entire list that the function is now live.

jungie71’s picture

Thank you for info.
My site isn't live yet so I have created couple of admin userID to test this out. In the process of testing, I have deleted and created organic groups constantly so
That might be problem.... but...
When I delete it, my db seems to delete the record just fine.
I can't find any deleted guild in og field.... Am I looking at the wrong field perhaps?

cartagena’s picture

These are the tables I cleaned up when I was experimenting:

And then everything worked fine. Of course, I was extremely careful to delete the right records, checking etids and gids and making sure I was deleting users and not nodes. Good luck!

bryancasler’s picture

Looks like another post I started might be a duplicate of this one. #1226586: A group membership is removed from a users account when they are added to another group

Taxoman’s picture

Version: 7.x-1.x-dev » 7.x-1.1

I am a bit confused with this issue; #13 and #18 seem to suggest there was a patch, but it is not present here, and the latter seems to indicate that the issue is closed, but it has never been closed and thus not re-opened (it is currently still open...). So if something has been merged with dev, then it is now part of version 1.1, can anyone confirm if this is still a problem in 1.1? It seems strange that 1.1 was released if this bug was still unsolved and "major".

bryancasler’s picture

The "fix" for this issue. Go to "admin/config/people/accounts/fields/group_audience" and set "GROUPS AUDIENCE FIELD SETTINGS" to "Unlimited"

Some of us found that this value was set to "1". This meant a user could only be a member of 1 group at a time.

I don't believe this issue was completely resolved, because if you leave the value at "1" a user can still be added/join other groups and a confirmation message will appear, but they won't actually be added. I also had a few cases where users would be added and appear as members, but the next day the would be purged from the groups membership. It's also not resolved because I believe the entire group audience field can be deleted without a warning being thrown. #1038232: Group Manager can't add users to group. Also, Group Manager doesn't have visibility to Group (for a node's Group Audience)

cartagena’s picture

In my case, I have group_audience set to 1 and a user can still join multiple groups and they do appear as group members in both groups. It just displays the most recent group they have joined. I am not a programmer but in fixing a double-membership problem I noticed that the etid field of the og_membership table allows for multiple values. If that field were unique, then the user and node etids could not be duplicated and a user could belong to only one group and a post could belong to only one group, correct? Would that be a way to go if you really want just one membership per user? Thanks.

amitaibu’s picture

Priority: Major » Normal
Status: Needs work » Active

> Would that be a way to go if you really want just one membership per user? Thanks.

One way would be to implement in a custom module hook_field_access() and deny viewing group-audience if user has already a group membership.

cartagena’s picture

Thanks so much, I think I can do that--at least I understand the concept. I'll post it when I get it figured out!

Sparhawk104’s picture

I also require users to only be able to subscribe to one group at a time, and I thought that would be easily accomplished by setting the allowed values of group audience to 1, but even though you can only select one group in the field, you can still subscribe to a second group through the subscribe link. Until the user account is edited and saved, the user will be listed in both groups despite there only being one value in group audience.

I've tried several workarounds involving flags and rules, but they are all foiled by the apparent behaviour of OG to reset any changes made to the user during an event where a user is subscribed to a group, as well as the inability to force redirect from node/*/subscribe pages. It's a real conundrum! ;)

I'd shower love and affection on anyone who can come up with a solution to this!

BrightBold’s picture

Like animelion, I wanted a situation where users could join multiple groups, but each piece of group content was limited to a single group. I don't understand the inner workings of OG, so I'm sure from a technical perspective there's a reason that the Group Audience field is used both to determine what groups someone is a member of and what content is associated with that group (I'm guessing it's because users and content are both entities, and OG is trying to create an entity type-agnostic relationship with groups?), but from a site-builder perspective it's confusing to have to treat the Group Audience field the same way when used in different contexts. Add me to the list of people who would shower love and affection on anyone who could come up with a way to improve this.

Taxoman’s picture

#33: I too sometimes have that need for certain web sites: to allow multiple groups per person, but limit content posts to be saved only into one group per post.

amitaibu’s picture

In #1342632: Deprecate OG group entity, I plan OG to be more strict with the field cardinality.

KorbenDallas’s picture

This is still an issue; it's actually two issues. Once either occurs, it's a serious issue with your database because it junks OG up quite badly. Luckily I found this issue before making my site live with OG. I see this was a problem for version 7.x-1.1 when this issue was originally logged. I have replicated it in 7.x-1.3 and 7.x-1.x-dev.

The 1st issue

My OG setup is very simple:

  • Users has the "Groups audience" field, default settings
  • A Group Node content type that has the "Groups" field, default field settings, and the "Group type" radio button selected.
  • An Event Node content type that has "Groups audience" and "Group content visibility" fields, default field settings, and "Group content type" radio button selected.

Here were my steps to recreate the 1st issue:

  1. Create new Group content, check the "Groups" field
  2. Delete the content you just created

The 'field_data_group_audience' and 'field_revision_group_audience' tables still have references to this deleted content. I'm going to branch into scenarios now assuming only the above, each scenario is mutually exclusive from each other:

Scenario1: If you create new Group content and check the "Groups" field, the 'og_membership' table will be populated with the new Group content you just created AND the previous one you deleted. Additionally if you have deleted several Groups, say 5, then all 5 groups will show up in the 'og_membership' table along with the new Group content you just created. This rogue data in the 'og_membership' further exasperates future issues when you go to delete more Groups.

Scenario2: (This is mutually exclusive from Scenario1.) Say you notice the leftovers in the 'field_data_group_audience' and 'field_revision_group_audience' tables then delete the dirty data out of them. If you create new Group content and check the "Groups" field, the 'og_membership' table will still be populated with the new Group content you just created AND all the previous ones you've deleted.

Either scenario presents a serious OG bug.

The 2nd issue

A similar, simple OG setup as before:

  • Users has the "Groups audience" field, default settings
  • A Group Node content type that has the "Groups" field, default field settings, and the "Group type" radio button selected.
  • An Event Node content type that has "Groups audience" and "Group content visibility" fields and "Group content type" radio button selected.
  • The Event Node field setting for the "Groups audience" field was changed from Number of values = Unlimited to Number of values = 1. Why? Because this looks like a simple form setting to restrict the Event Node type selection box, not some date field restriction setting. I left the default field setting for "Group content visibility".

Here were my steps to recreate the 2nd issue:

  1. Create new Group content, check the "Groups" field
  2. Create a second new Group content, check the "Groups" field
  3. Create a third new Group content, check the "Groups" field

Upon the second new Group content, the 'og_membership' table had two records in it. The third new Group content addition deletes the second Group content from the 'og_membership' table (!!!!), then inserts the third new Group content. To carry this one step further, if you add a fourth new Group content it will again delete the previous 'og_membership' table record!!!
This doesn't make logical sense because the 'Number of values' setting was done on the Event, a "Group content type", and this setting is affecting the behavior on the Group, a "Group type". Note that this behavior happens with no Event content created at all, so it has nothing to do with associating the Event to a Group.
Furthermore, I created a Group2 "Group content type", and I got the same behavior on Group2!

This is also a serious OG bug!

Issues 1 and 2 combined

This is where things get really nasty. The 1st issue represents a bug such that records are being inserted into OG tables when they should not be. The 2nd issue represents a bug such that records are being deleted from OG tables when they should not be. Both of these issues combined junks up the installed OG environment on your website.

My work-arounds

Work-around to Issue #1
I used OG's API for hook_group_delete to fix my deletion problem. I'm not an expert in OG, so your OG setup might have more field tables that need their dirty data removed. Important! Note his code has a call to drupal_flush_all_caches() because if you just merely delete the dirty data out of the tables, issue #1 will still occur. Also if your tables are non-transactional then you'll want to remove the transaction condition:

* Implements hook_group_delete
* Responds to OG group deletion.
* This hook is invoked after the OG group has been removed from the database.
* @param OgGroup $og_group
*   The OG group that is being deleted.
* @see hook_entity_delete()
function MYMODULE_group_delete(OgGroup $og_group) {

	// Create a db_transaction
	$MYMODULE_group_delete_transaction = db_transaction();
		->condition('group_audience_gid', $og_group->gid)

		->condition('group_audience_gid', $og_group->gid)
	catch (Exception $e) {
		watchdog_exception('MYMODULE', $e, 'MYMODULE_group_delete_transaction');

Work-around to Issue #2
Post #15 and #16 prescribe the work-around for this issue, don't touch the 'Number of values' setting, leave it at 'Unlimited' and theme around it.

jgraham’s picture

I think this is still relevant in the 2.x branch;

several group content types: team, club
several group-post content types: announcement, event, group-page

Desired configuration;
each group-post (announcement, event, group-page) etc. is allowed to be in exactly one team or club.
site members should be allowed to join any number of teams or clubs

Upon setting the group_audience cardinality to 1 you can no longer add content of type team or club failing with the following error

OgException: There are no OG fields in entity user and bundle user referencing node - julio_club. in og_group() (line 1701 of /srv/www/vbdev/html/profiles/julio/modules/og/og.module).

I have checked and rechecked that the user entity does in fact have the groups audience at 'admin/config/group/fields'.

It seems that the issue is that nodes and users are both sharing the og_audience field and thus are conflicting with the desired config. Maybe I missed something in the config and this is possible?

Changing the field cardinality to unlimited allows club and team nodes to be created without issue.

Related issue #1482562: Error when trying to add a new group type.

amitaibu’s picture

Regarding 2.x:

> Upon setting the group_audience cardinality to 1 you can no longer add content of type team or club failing with the following error

To achieve what you need:
You can keep the og

  • _group_ref attached to the nodes set to cardinality == 1.
  • Remove the og_group_ref from the user, and manually add a new field (call it what you want e.g. og_user_group_ref) and set cardinallty to Unlimited

As you can see, OG7-2 now no longer has group-audience field name hardcoded, so you can add as many fields as needed, and configure them differently.

amitaibu’s picture

Status: Active » Fixed

As this is fixed in 2.x, setting status.

markwk’s picture

@Amitaibu: just to be clear: this fix of creating a separate field like og_user_group_ref will only work 2.x branch?

I hate to add any additional work for anyone and hopefully I can upgrade to the 7.x-2.x eventually, but the structural change doesn't make a clean upgrade path for the tons of views and a couple couple modules needed on my site with OG.

Anyways, without ruining anything how complicated would it be to backport a solution like this be? It surprised when I came across this issue about og audience field not having flexiblity to be unlimited in one situation and limited in another.

KorbenDallas’s picture

What about Issue #1 I reported in comment #36?

markwk’s picture

@KorbenDallas: I'm not really sure what you mean... maybe my brain isn't quite fully processing all of this.

amitaibu’s picture

> @Amitaibu: just to be clear: this fix of creating a separate field like og_user_group_ref will only work 2.x branch?


> Anyways, without ruining anything how complicated would it be to backport a solution like this be?

Very + I'm not going to do it :)

KorbenDallas’s picture

@markwk Sorry, the question was meant for Amitaibu

@Amitaibu Have you had to chance to look at Issue #1 I reported in comment #36? It still remains unaddressed..

Vasu’s picture

#38 -Remove the og_group_ref from the user, and manually add a new field (call it what you want e.g. og_user_group_ref) and set cardinallty to Unlimited

Is there any way to do this without losing the field data ?

Taxoman’s picture

Version: 7.x-1.1 » 7.x-2.x-dev
amitaibu’s picture

You can add the new field, and create a Drush script to copy from one field to another.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

lofos1’s picture

Status: Closed (fixed) » Active

Reopening cuz I'm running into a problem with group limits and displaying the Subscribe to Group link.
When I limit a user's group membership to 1 group, the 'Subscribe to Group' link does not display on the group page to users who have not yet joined any group.

Scenario 1: Steps to Reproduce
- Create Group-1 as User A.
- Login as User B and join Group-1
- Change the Group membership limit on user account settings to 1
- Login as User B and unsubscribe from Group-1, then attempt to Subscribe again --> Subscribe to Group link does not display
- Login as User C and access Group-1 page --> Subscribe to Group link does not display

If I set the limit to 2 groups, then this works as expected.
Scenario 2: Steps to Reproduce:
- Change the Group membership limit on user account settings to 2
- Create Group-1 & Group-2 as User A, and Group-3 as User B.
- As User C, subscribe to Group-1 & Group-2, and attempt to subscribe to Group-3 --> Subscribe to Group link does not display on Group-3.
- Unsubscribe User C from Group-2, then access Group-3 page --> Subscribe to Group link displays

Other than theming (Post #15 & #16) around for the 1 group limit, is there a way to have OG work the same way in scenarios 1 & 2 above? Thanks.

wuh’s picture

I have read through this issue thoroughly and am looking for some clarification regarding an error I'm seeing.

If I change my og_group_ref field (groups audience) 'Number of values' from unlimited to 1, I get the following error when I try to create a group post, the error prevents the node from being created:

EntityMetadataWrapperException: Invalid data value given. Be sure it matches the required data type and format. in EntityDrupalWrapper->set() (line 744 of /Users/huwroberts/Sites/

Several comments suggest that this error is thrown because changing the field's settings on the group content content type also changes the settings on the user profile. However, I've checked and the groups audience field used on the user profile is a different field with distinct settings.

Is this a bug, expected behaviour or down to some misconfiguration? Is there a known workaround to restrict posting of group content to a single group?

pjbarry21’s picture

wuh - Did you ever figure out the issue with this (above):

I'm running into this now and did have one the number of values set to 1. Changed it back to unlimited, but still getting the error. Had been working fine before (don't even remember changing the value from unlimited to 1).

  • amitaibu committed 717310e on 8.x-1.x
    #1203466 reported by cartagena: Can't use og_group() when group-audience...