Problem/Motivation

If someone wants to turn on entity validation for a migration, then you need to run the drush command as the root user. Otherwise simple things like filter format allowed values list will fail validation because you only give "Full HTML" to admins and "Restricted HTML" and/or Plain Text to anonymous users. By default, Drush runs as anonymous. Let's fix this.

Proposed resolution

This could lead to some possible problems, if someone was relying on the fact that migrations run as anonymous. So let's see if others feel this needs a way to toggle this automatic feature off.

Remaining tasks

User interface changes

API changes

Data model changes

Release notes snippet

Command icon 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

heddn created an issue. See original summary.

heddn’s picture

Status: Active » Needs review
StatusFileSize
new2.17 KB
andypost’s picture

Default content module using the same approach

heddn’s picture

I copied from default_content :smile:

wim leers’s picture

Interestingly, I have not run into this problem. What is the concrete entity validation constraint that is failing without this?

heddn’s picture

@Wim Leers, it is on text filters/formats. Full HTML is secured to only admin users. But drush runs everything as anonymous. And my content has a very common thing called a body field and entity validation running as anonymous fails validation. It isn't an issue running from migrate_drupal_ui, as it requires you to run the upgrade as user=1.

andrewmacpherson’s picture

Some other scenarios I've encountered...

It fails on entity reference for the ownership of the referenced entity.

  • A migration which create some file records, and assign them to user 1 using the default_value process plugin
  • A later migration creates media items where an image field refers to the file...
  • ... entity validation during migration fails with the message: "[media: 341]: field_media_image.0=You do not have access to the referenced entity (file: 341)"

Path alias migrations can fail validation too: "\[path_alias: 12842, revision: 1533\]: path.0.value=Either the path '/node/14' is invalid or you do not have access to it."

FWIW, I'm happily using the patch here on a personal project. It fixes both the scenarios I've mentioned here.

I'm aware of the related core patch, but it's rolled against 9.1.x and I'm not ready for D9 yet.

I assume the file entity reference scenario could also be a problem for migrating the imagefield on a D7 standard profile article, migrating to a D8 standard profile article.

heddn’s picture

Status: Needs review » Closed (duplicate)

The great Gitlab migration is upon us. Please post your comments to https://gitlab.com/drupalspoons/migrate_tools/-/issues/75 in the future.

joekers’s picture

I'm not sure drupalspoons is still the place to post comments on this, it looks pretty quiet over there, but apologies if so.

The patch is working well for me. I also needed it for the text filter format and to handle a content moderation workflow error.

ludo.r’s picture

phma’s picture

Status: Closed (duplicate) » Reviewed & tested by the community

#2 works for me when importing nodes with a default moderation state. Else I either have to disable content moderation or give workflow access to the anonymous user.

robertom’s picture

StatusFileSize
new2.19 KB

Reroll patch.

osab’s picture

#12 works fine for me also, D10.1.5 php8.1. It fixed the error 'User %user not allowed to go from state %sid1 to %sid2' from workflow module, as it made migrate as anonymous.

joachim’s picture

> @Wim Leers, it is on text filters/formats. Full HTML is secured to only admin users. But drush runs everything as anonymous. And my content has a very common thing called a body field and entity validation running as anonymous fails validation. It isn't an issue running from migrate_drupal_ui, as it requires you to run the upgrade as user=1.

Furthermore, with entity types that don't have an owner such as block_content, EntityContentBase::validateEntity() won't do any account switching.

heddn’s picture

Status: Reviewed & tested by the community » Needs work

Instead of defaulting to user=1, let's make this a configurable for _which_ user we want to execute as. Similar to how drush used to work .i.e. drush mim --uid=33 my_migration. My logic being that user=1 is no longer always a full admin user since https://www.drupal.org/node/2910500

vasike made their first commit to this issue’s fork.

vasike’s picture

Version: 8.x-5.x-dev » 6.0.x-dev

vasike changed the visibility of the branch 3134245-run-drush-imports-uid-option to hidden.

vasike’s picture

Status: Needs work » Needs review

Created a MR with new uid option for import only using the account_switcher service.

I tested within a project doing Migrate Source CSV dependant migration imports, using ECA Models to control different entities data.
And it worked as expected.
Needs review ... for now ... to get some feedback.
Do we need also for other "commands"?

Note: For ECA models "alteration" this could also achieved, but currently the option is to have the user set for all models ...

Also it seems the issue was previously for an older version, so initially I created a "bad" branch
which seems I can't delete it
https://git.drupalcode.org/issue/migrate_tools-3134245/-/tree/3134245-ru...

vasike’s picture

Title: Run drush imports as user=1 » Run drush imports as administrator users
emanaton’s picture

Reroll of patch for version 6.1.2.

heddn’s picture

Issue tags: +Needs reroll

MR needs a rebase

heddn’s picture

Version: 6.0.x-dev » 6.1.x-dev
Status: Needs review » Needs work

I like the idea here. This should help in certain situations. Needs a quick rebase. Ideally we'd add test coverage. I think that is possible.