I want to send an invitation, I get an error after submit

Created on 29 June 2023, over 1 year ago
Updated 12 July 2024, 4 months ago

Problem/Motivation

I want to send an invitation, I get an error after submit:
Drupal\Core\Entity\EntityStorageException: SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'name' cannot be null: INSERT INTO "users_field_data" ("uid", "langcode", "preferred_langcode", "preferred_admin_langcode", "name", "pass", "mail", "timezone", "status", "created", "changed", "access", "login", "init", "default_langcode", "rh_action", "rh_redirect", "rh_redirect_response", "rh_redirect_fallback_action")

Steps to reproduce

  1. Go to "/group/%/content/add/group_invitation"
  2. Fill "name" and "Email", click "Submit"
πŸ› Bug report
Status

Closed: works as designed

Version

4.0

Component

Code

Created by

πŸ‡·πŸ‡ΊRussia antiden

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

Comments & Activities

  • Issue created by @antiden
  • Status changed to Postponed: needs info over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium lobsterr

    Assume name is custom field you have on group content type for invitation plugin ?
    We don't insert any user on submit of this form, I guess some custom code is executed.
    I just tested it on the fresh installation it works as it should. Please double check your side

  • πŸ‡·πŸ‡ΊRussia antiden

    Hi,

    ok, find problem. I have installed module: remove_username β†’ and that caused the error, because this module is removing the 'name' (username) field from the user management forms.

    Your module is working well.

    With regards.

  • Status changed to Closed: works as designed over 1 year ago
  • πŸ‡§πŸ‡ͺBelgium lobsterr

    Glad you find the issue! Cheers

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

    @antiden - What did you end up doing? We're using the same combination of modules. I found that when I remove the presave hook in the remove_username module, the invitation is successfully created. I can't quite figure out what is causing the conflict between this module and the remove_username module...

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

    Aha! There is no email value in the `$user` object.

    The presave is setting a null value to the name...

    /**
     * Implements hook_ENTITY_TYPE_presave().
     */
    function remove_username_user_presave(UserInterface $user) {
      $user->setUsername($user->getEmail());
    }
    
  • πŸ‡ΊπŸ‡ΈUnited States johnnydarkko

    Found that after the group membership is invoked by the ginvite module and is saved into the database, an anonymous user object is passed into a user save call.

    Source: `web/modules/contrib/group/src/Entity/GroupRelationship.php line 262.`

    Before the anonymous user is saved, the remove_username attempts to copy the email value (in this case, NULL) to the username value, the database error occurs.

    I created an issue in the remove_username module that would prevent this from happening: https://www.drupal.org/project/remove_username/issues/3396469 πŸ› SQL Error when email is null Active

  • πŸ‡ΊπŸ‡¦Ukraine blade_ukraine

    It's also can happen because of the next issue https://www.drupal.org/project/email_registration/issues/3461071 πŸ› Save invite to group for anonymous user by email produce the error. Needs review

Production build 0.71.5 2024