Problem/Motivation
Hi, I've used feeds to import users for a while, so I feel like I've got the process down pretty well, but today I tried to import users with roles in a CSV file and the feed is returning the error:
The role role_machine_name cannot be assigned because it does not exist.
Except, the role does exist. I copied the machine name of the role (I also tried the user-friendly name) and pasted it into the CSV column directly to make sure I wasn't misspelling it or anything. Under Mapping, I made sure the role I want is selected for the import process.
I'm not dealing with multiple roles per user, so I didn't setup a tamper.
Steps to reproduce
Create a CSV with username, email, roles, and other fields you want
Create a feed
- Processor: Import new users, Update existing users
Map the fields to the user roles
Attempt import
Note warning errors that the role doesn't exist.
Proposed resolution
Remaining tasks
User interface changes
API changes
Data model changes
Issue fork feeds-3441669
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
ptmkenny commentedI am having the same issue. I will attempt to find the bad commit, but when I edit the mappings for Role, I can no longer select "id", only "UUID" or "User role weight".
Comment #3
ptmkenny commentedIn my exported config:
So it looks like the id reference got removed, but when? I also confirmed this behavior in the latest dev; it is no longer possible to reference roles by machine_name, but that is the most convenient way to do so.
Comment #5
ptmkenny commentedOk, I found the cause of the bug. ConfigEntityReference.php is not checking for id if there are mapping definitions, only UUID.
I think everything in Drupal has an id and a UUID, so I modified the code to assume everything does and simplify the logic. But, I don't know if this is actually a safe assumption. Let's see what the tests say, and please review.
Comment #6
megachrizThe issue is actually that Drupal 10 apparently added some new data types for config schema. Data types 'machine_name' and 'required_label' are new.
Config schema for user role in Drupal 9:
And in Drupal 10:
So changes in Drupal core broke this in Feeds.
Comment #7
megachrizFrom https://www.drupal.org/node/3349638:
Hm, that's not true for Feeds!
Besides machine_name, other newly introduced types don't seem to be significant for Feeds: https://www.drupal.org/list-changes/drupal/published?keywords_descriptio...
Comment #8
megachriz@ptmkenny
A config entity doesn't always have an 'id' property, but it does have an 'uuid' property:
So I reverted your changes in the MR.
Comment #9
ptmkenny commentedThank you so much for the explanation and better solution.
I have a site that can be initialized and all of the content is imported from feeds, so I tested the updated MR there. All the roles were imported correctly, so marking RTBC.
Comment #11
megachrizCool. Thanks for testing! I merged the code.
Comment #13
ronraney commentedHello - I think I have the same issue. I updated the module. I tried using the machine name and mapping to ID. In Devel, the id is the same as the machine name. That didn't work. I am now going to try mapping the UUID to the UUID. Is that the proposed solution once the module is updated?
Comment #14
megachriz@rraney
When mapping to user roles, it makes the most sense to reference roles by ID or by label. But you could use UUID as well. When on Drupal 10, you need Feeds 8.x-3.0-beta5 or later to configure the role target in the UI.