Import fails if a referenced user already exists

Created on 19 March 2024, 8 months ago
Updated 17 April 2024, 7 months ago

Problem/Motivation

I want to export/import a default node and/or taxonomy term containing a user reference field, which will contain the default value of admin (1). The import fails if the user already exists.

> In StatementWrapperIterator.php line 111:
>                                                                                                          
>   SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry 'admin-en' for key 'user__name'

Steps to reproduce

  1. Add a user reference field to a node type
  2. Create a node that references the admin user from the user reference field
  3. Export the node from one environment
  4. Import the node in another
  5. Experience the error

Proposed resolution

Allow content that references a user to be imported without trying to create users that already exist (maybe reference users by entity id)

πŸ› Bug report
Status

Needs work

Version

1.4

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States MegaKeegMan

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

Comments & Activities

  • Issue created by @MegaKeegMan
  • Assigned to kyriazo
  • Status changed to Postponed: needs info 8 months ago
  • Tested on Drupal 10.2 with php 8.2 and works correctly. Can you give more feedback in order to reproduce the issue? Can you reproduce it on a clean environment?

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

    Yes. The issue is that the uuid of the admin user is different between instances, so it tries to create a new user with the same name. So I guess I could just update the uuid to reflect the admin on the separate instance. Just a minor inconvenience.

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

    I am trying to use this to generate default content for a distribution though. I could write a script that gets the uuid of the admin, updates the uuid in each default content zip, and then imports. But I guess the alternative is whether the import needs to respect the uuid of the referenced user, or if it could just infer that information based on the user with the given username. Any different ideas or suggestions?

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

    Maybe a big ask but a token would be cool

  • Assigned to nginex
  • Status changed to Needs work 7 months ago
  • πŸ‡ΊπŸ‡¦Ukraine nginex

    I think this should be improved in doImport() method, at least we can have an extra validation by loading users by email and username if entity by uuid was not found. I will provide a patch, once it's available, there will be nothing to do on your side, I'm also planning to provide a new release soon, so the patch will be included to the new release immediately

  • πŸ‡ΊπŸ‡¦Ukraine nginex
Production build 0.71.5 2024