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

Created on 18 August 2025, about 2 months 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

Merge Requests

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? 🤔

  • First commit to issue fork.
  • 🇺🇸United States byronveale

    Attaching patch for testing.

  • 🇺🇸United States byronveale

    Adding updated patch with latest commit.

  • Merge request !221Resolve #3541890 "Entity validation should" → (Open) created by byronveale
  • 🇺🇸United States byronveale

    This is working for me.

    I did find another instance of switchAccount(), in FeedQueueWorkerBase.php. I did not find when this code is called.

  • Pipeline finished with Failed
    about 1 month ago
    Total: 362s
    #591310
  • 🇺🇸United States byronveale

    Saw that tests failed.

    Regarding phpunit

    If I’m reading this right, it failed at line #159 in FeedsExecutable.php, which is where I removed what I thought was an unnecessary if statement that checked if owner_id was set, as in my testing, I could not create a Feed type with this field empty, the default Anonymous user was always entered if I did not manually enter something. Presuming this is indeed the cause of the “Call to a member function getProcessor() on null” error. What am I missing here?

    Regarding the next phpunit (next minor)

    It looks like this also failed at line #159, so same issue.

    Regarding the next phpunit (previous major)

    It looks like this also failed at line #159, in addition to failing elsewhere.

    Regarding the next phpunit (previous minor)

    It looks like this also failed at line #159.

    So it seems like adding back the if statement I removed would fix these things, but I would like some clarification as again, I could not create a Feed type with no value in the owner_id field. Want to make sure I’m looking in the right places…

  • Pipeline finished with Failed
    27 days ago
    Total: 370s
    #594111
  • Pipeline finished with Failed
    26 days ago
    Total: 372s
    #594130
  • Pipeline finished with Failed
    26 days ago
    Total: 1343s
    #594193
  • Pipeline finished with Failed
    25 days ago
    Total: 576s
    #595407
  • Pipeline finished with Failed
    25 days ago
    Total: 369s
    #595426
  • Pipeline finished with Running
    25 days ago
    #595455
  • Pipeline finished with Failed
    25 days ago
    Total: 340s
    #595471
  • Pipeline finished with Failed
    16 days ago
    Total: 622s
    #603491
  • Pipeline finished with Failed
    16 days ago
    #603556
  • Pipeline finished with Running
    16 days ago
    #603606
  • Pipeline finished with Success
    16 days ago
    #603627
  • Pipeline finished with Success
    5 days ago
    Total: 447s
    #614380
Production build 0.71.5 2024