Entity validation should occur as the owner of the feed item, not the feed

Created on 18 August 2025, 1 day ago

Problem/Motivation

Feeds allows specifying the owner of the imported items. Either you can configure it so that the owner of imported items are inherited from the feed entity, or you can specify a specific user to use instead.

When you specify a specific user, that user isn't used for entity validations. Before Feeds processes items for import (or any other feeds action), it uses Drupal's AccountSwitcher service to switch to the owner of the feed entity. I think it would be more appropriate to switch to the user that will be the owner of the imported item, which may not be the same person.

Steps to reproduce

This was my scenario:

  • Have a feed setup and indicate the owner of imported items should be user 1, NOT the owner of the feed itself
  • Block user 1 account (common setup on many sites)
  • Create a new account that has permission to create feeds and create a feed as that user
  • After that account is created, remove any role from that user that gives them priviledged access to anything (essentially just make them authenticated user)
  • Observe that when feed importer runs, you get a validation error when importing a new item. Feeds tries to set the owner of the imported item to "user 1" as instructed, but it's running the validations as the other user which now no longer has access to reference other users. Item doesn't import.

That's my scenario which is a little weird, but it happens sometimes because the people that created the feed may leave the department and their roles are stripped. The feed suddenly stops importing items because that user no longer has the ability to reference other content on the site.

Proposed resolution

If the feed is configured to have a specific owner specified for imported items, switch to that account before processing anything. This is most impactful for feeds processing, as that's where the entity validations run.

Remaining tasks

User interface changes

API changes

Data model changes

πŸ› Bug report
Status

Active

Version

3.0

Component

Code

Created by

πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

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

Comments & Activities

  • Issue created by @bkosborne
  • πŸ‡³πŸ‡±Netherlands megachriz

    If I'm not mistaken, Feeds does a second account switch (to the owner of the item) when you enable the "Authorize" option. I'm on mobile right now, so it's harder to check for me now if that is the exact option that triggered the second account switch, but at least there exists a second account switch in the code.

  • πŸ‡ΊπŸ‡ΈUnited States bkosborne New Jersey, USA

    Hmm, the only place I see in the code where an account is switched is FeedsExecutable->processItem()

  • πŸ‡³πŸ‡±Netherlands megachriz

    I quickly scanned the code of EntityProcessorBase in the web interface and cannot find that second account switch right now. But I was pretty sure that I had made that. Did I perhaps only implement that for the D7 version of Feeds? πŸ€”

Production build 0.71.5 2024