Bug #67274

initializeObject() called before dependency injection

Added by Morton Jonuschat about 6 years ago. Updated almost 4 years ago.

Status:
Closed
Priority:
Must have
Assignee:
-
Category:
Extbase
Target version:
Start date:
2015-06-03
Due date:
% Done:

100%

Estimated time:
TYPO3 Version:
6.2
PHP Version:
5.5
Tags:
Complexity:
Is Regression:
No
Sprint Focus:
Stabilization Sprint

Description

Given typical extbase controller actions:

    public function listAction() {
        $records = $this->modelRepository->findAll();
        $this->view->assign('records', $records);
    }

    public function showAction(Model $model) {
        $this->view->assign('model', $model);
    }

The method initializeObject() on the Models is called before the dependency injection has been performed. According to http://wiki.typo3.org/Dependency_Injection#initializeObject.28.29_as_object_lifecycle_method `initializeObject()` is called after DI has been done.

Tested on 6.2.12


Related issues

Related to TYPO3 Core - Bug #67272: initializeObject() not called for Extbase Domain ModelClosed2015-06-03

Actions
Related to TYPO3 Core - Bug #61044: AbstractDomainObject::__wakeup() method should not call initializeObject method internallyClosedDaniel Hürtgen2014-08-18

Actions
Related to TYPO3 Core - Bug #67401: Document "DI is now done before initializeObject" as important .rstClosed2015-06-10

Actions
#1

Updated by Morton Jonuschat about 6 years ago

Also affects TYPO3 7.2.0

#2

Updated by Morton Jonuschat about 6 years ago

On 6.2.13-dev initializeObject() is not being called anymore - see #67272.
Seems to be related to the Doctrine Migrator changes.

#3

Updated by Gerrit Code Review about 6 years ago

  • Status changed from New to Under Review

Patch set 1 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914

#4

Updated by Gerrit Code Review about 6 years ago

Patch set 2 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914

#5

Updated by Gerrit Code Review about 6 years ago

Patch set 3 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914

#6

Updated by Xavier Perseguers about 6 years ago

  • Target version set to 6.2.13
  • Sprint Focus set to Stabilization Sprint
#7

Updated by Gerrit Code Review about 6 years ago

Patch set 4 for branch master of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/39914

#8

Updated by Morton Jonuschat about 6 years ago

  • Status changed from Under Review to Resolved
  • % Done changed from 0 to 100
#9

Updated by Gerrit Code Review about 6 years ago

  • Status changed from Resolved to Under Review

Patch set 1 for branch TYPO3_6-2 of project Packages/TYPO3.CMS has been pushed to the review server.
It is available at http://review.typo3.org/40056

#10

Updated by Helmut Hummel about 6 years ago

  • Status changed from Under Review to Needs Feedback

Morton Jonuschat wrote:

On 6.2.13-dev initializeObject() is not being called anymore - see #67272.
Seems to be related to the Doctrine Migrator changes.

If you tested that on 6.2.12, how can this be related to Doctrine Instantiator changes? These were not included in that release.

Can be please be very clear about that? Your issue is present before the Doctrine instatiator change, right?

#11

Updated by Helmut Hummel about 6 years ago

Helmut Hummel wrote:

Morton Jonuschat wrote:

On 6.2.13-dev initializeObject() is not being called anymore - see #67272.
Seems to be related to the Doctrine Migrator changes.

If you tested that on 6.2.12, how can this be related to Doctrine Instantiator changes? These were not included in that release.

Can be please be very clear about that? Your issue is present before the Doctrine instatiator change, right?

This very bug has nothing to do with the Doctrine instatiator change. Even before the initializeObject was called in __wakeup of domain objects and DI was done after that (since very long already)

#12

Updated by Morton Jonuschat about 6 years ago

To be very clear:

Given the following Class:

class Event extends AbstractEntity {
    /**
     * @var \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface;
     */
    protected $configurationManager;

    /**
     * inject the configurationManager
     *
     * @param \TYPO3\CMS\Extbase\Configuration\ConfigurationManagerInterface $configurationManager
     * @return void
     */
    public function injectConfigurationManager(ConfigurationManagerInterface $configurationManager) {
        print "<pre>injectConfigurationManager</pre>";
        $this->configurationManager = $configurationManager;
    }

    /**
     * Tasks to perform on object initialization
     *
     * @return void
     */
    public function initializeObject() {
        print "<pre>initializeObject</pre>";
        $this->settings = $this->configurationManager->getConfiguration(ConfigurationManagerInterface::CONFIGURATION_TYPE_SETTINGS);
    }
}

On 6.2.12

Output:

initializeObject

followed by a PHP Fatal error since $this->configurationManager has not been injected yet

This is what THIS bug report was about

On 6.2.13-dev
I'd get the following Output:

initializeObject

Later on $this->settings would be empty since initializeObject() has not been called at all.

The comment you quoted is related to the observation that there is a different bug on 6.2.13-dev that skips initializeObject() alltogether - #67272
I was asked to verify this against 6.2.13-dev on Slack to see if the switch to Doctrine Instantiator fixed it.

#13

Updated by Morton Jonuschat about 6 years ago

Sorry, on 6.2.13-dev the output was

injectConfigurationManager

Dumb copy&paste error

#14

Updated by Alexander Opitz about 6 years ago

  • Target version changed from 6.2.13 to 6.2.14

After Reverting DI in 6.2.13, is this issue still valid?

#15

Updated by Morton Jonuschat about 6 years ago

Yes, this issue ist still valid as nothing has changed in 6.2.13 in this regard (The switch to doctrine instantiator has been reverted, so initializeObject() is being called in __wakeup() which happens before the dependency injection).

#16

Updated by Alexander Opitz about 6 years ago

  • Status changed from Needs Feedback to New
#17

Updated by Christian Kuhn about 6 years ago

  • Status changed from New to Resolved

the issue is fixed in master and will not be fixed / changed in 6.2

#18

Updated by Riccardo De Contardi almost 4 years ago

  • Status changed from Resolved to Closed

Also available in: Atom PDF