Problem/Motivation

We should not perform any logic (like retrieving entity storage handlers) while constructing services. The constructors are executed when the dependency injection container is built and this can have unintended side effects.

I'm getting a fatal error when doing a clean install using existing config: Call to undefined function \paragraphs_entity_type_alter() which can be traced back to the instantiation of the Masquerade class during container building. It tries to get the user storage from the entity type manager, which calls EntityTypeManager->findDefinitions() which in turn calls DefaultPluginManager->alterDefinitions() which finally throws the fatal error since this code is not functional with a half built DI container.

Moral of the story: do not call code in constructors that has the potential to fire hooks.

Steps to reproduce

This can be quite tricky to reproduce. I get it when installing a project from existing config. I did not narrow this down to a minimal set of modules.

Proposed resolution

Do not perform logic when constructing services.

Issue fork masquerade-3572640

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

pfrenssen created an issue. See original summary.

andypost’s picture

looks like good idea

pfrenssen’s picture

Status: Active » Needs review

Thanks! I have made the change. The test failure is unrelated.

andypost’s picture

Looks that's only place to fix, thank you!

Gonna merge later this week

  • andypost committed e5f4bfb0 on 8.x-2.x authored by pfrenssen
    feat: #3572640 Do not perform logic in constructors
    
    By: pfrenssen
    
andypost’s picture

Status: Needs review » Fixed

Merged, thank you

Now that this issue is closed, review the contribution record.

As a contributor, attribute any organization that helped you, or if you volunteered your own time.

Maintainers, credit people who helped resolve this issue.

mkalkbrenner’s picture

You should consider a new release quickly. Masquerade breaks commerce 3.3.

andypost’s picture

facine changed the visibility of the branch 3572640-avoid-logic-in-constructors to hidden.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.