Field group_roles is unknown

Created on 11 February 2025, 7 months ago

Problem/Motivation

After installing the module. I set up a group type with two fields. When saving it I get the "Attempt to create a field without a field_name" error. It does create the group type. When I then try and create a group, I get this error:

InvalidArgumentException: Field group_roles is unknown. in Drupal\Core\Entity\ContentEntityBase->getTranslatedField() (line 616 of core/lib/Drupal/Core/Entity/ContentEntityBase.php).

Drupal\Core\Entity\ContentEntityBase->get() (Line: 91)
Drupal\group\Entity\Storage\GroupRoleStorage->loadByUserAndGroup() (Line: 41)
Drupal\group\Entity\GroupMembership->getRoles() (Line: 90)
Drupal\group\GroupMembership->getRoles() (Line: 64)
Drupal\group\Access\IndividualGroupPermissionCalculator->calculatePermissions() (Line: 138)
Drupal\flexible_permissions\ChainPermissionCalculator->calculatePermissions() (Line: 41)
Drupal\group\Access\GroupPermissionCalculator->calculateFullPermissions() (Line: 40)
Drupal\group\QueryAccess\GroupQueryAlter->doAlter() (Line: 143)
πŸ› Bug report
Status

Active

Version

3.3

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States jeffreysmattson

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

  • Issue created by @jeffreysmattson
  • πŸ‡ΊπŸ‡ΈUnited States jeffreysmattson
  • πŸ‡ΊπŸ‡ΈUnited States jeffreysmattson
  • πŸ‡ΊπŸ‡ΈUnited States jeffreysmattson
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Can you provide steps to reproduce on a clean install?

  • πŸ‡ΊπŸ‡ΈUnited States jeffreysmattson

    I had installed the module using composer and then enabled this module using config. This doesn't run the install hook so the module was not installed correctly.

    The solution was this:

    1. Installed the module with composer.
    2. In the UI or using Drush enabled the module.
    3. Exported the configs.
    4. Module works as expected after site creation and config import.
    5. Profit.

    This is something that people may not know about Drupal. I sure didn't.

  • πŸ‡ΊπŸ‡ΈUnited States jeffreysmattson
  • πŸ‡§πŸ‡ͺBelgium kristiaanvandeneynde Antwerp, Belgium

    Thanks for updating the issue with your findings. Not everyone does that so I really appreciate it.

  • πŸ‡ΊπŸ‡ΈUnited States barbarae

    3 months to figure out this issue:

    Here is the solution we used:

    drush ev "
    use Drupal\field\Entity\FieldConfig;
    
    FieldConfig::create([
      'field_name' => 'group_roles',
      'entity_type' => 'group_relationship',
      'bundle' => 'administrators-group_membership',
      'label' => 'Group roles',
      'required' => FALSE,
      'settings' => [],
    ])->save();
    "

    This worked!

    so, replace "administrators" with your group machine name and run the script. It creates the missing group_roles . Only do this if you are actually missing the group_roles.

    The need for this fix was due to a botched hook update execution along the way somewhere , or botched upgrade. We ran this script to avoid having to re-install from scratch. Now the /admin/group route loads without crashing although we did have to reload our opcache (apcu) and rebuild drupal cache also.

  • πŸ‡ΊπŸ‡ΈUnited States barbarae

    Ideally the hook_update would handle sanity checks and ensure the expected group_roles exist.

  • Status changed to Needs review about 2 months ago
  • πŸ‡ΊπŸ‡ΈUnited States vlyalko

    I am having the same issue with the upgrade of the group module to 3.3.5 version.
    On the first load of the site i got the error for the flexible_permissions discussed here https://www.drupal.org/project/group/issues/3484817 πŸ› Updating from 3.2.2 to 3.3.0 makes site inaccessible. Active .
    Cleared cache and was able to get to the login screen. After login in, I am getting the same error from this issue. Tried to do what was recommended in #6, but i am getting warning that 'field_config' entity with ID 'group_relationship.ahrc_pl_hrc_g_3-group_membership.group_roles' already exists.'

    Trying to clear cache multiple times. Still the same error.

Production build 0.71.5 2024