Skip to content

[FrameworkBundle] Autoconfigure ORM attributes only if not done by DoctrineBundle #60001

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -771,15 +771,19 @@ static function (ChildDefinition $definition, AsPeriodicTask|AsCronTask $attribu
$container->registerAttributeForAutoconfiguration(AsMessage::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.messenger.message');
});
$container->registerAttributeForAutoconfiguration(Entity::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.entity');
});
$container->registerAttributeForAutoconfiguration(Embeddable::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.embeddable');
});
$container->registerAttributeForAutoconfiguration(MappedSuperclass::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.mapped_superclass');
});

// DoctrineBundle autoconfigures attributes since version 2.14.0
if (!array_key_exists(Entity::class, $container->getAutoconfiguredAttributes())) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure this is resilient if the DoctrineBundle is registered before FrameworkBundle. We can check the package version instead.

Suggested change
if (!array_key_exists(Entity::class, $container->getAutoconfiguredAttributes())) {
if (InstalledVersions::isInstalled('doctrine/doctrine-bundle') && version_compare(InstalledVersions::getVersion('doctrine/doctrine-bundle'), '2.14.0', '<')) {

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is not resilient at all irrespective of the order, because DI extensions receive a separate container builder (which is then merged into the main one), precisely to reduce the cases of writing logic that depends on the order (which is not guaranteed at all by Flex)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the composer version check better?

$container->registerAttributeForAutoconfiguration(Entity::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.entity');
});
$container->registerAttributeForAutoconfiguration(Embeddable::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.embeddable');
});
$container->registerAttributeForAutoconfiguration(MappedSuperclass::class, static function (ChildDefinition $definition) {
$definition->addExcludeTag('container.excluded.doctrine.mapped_superclass');
});
}

$container->registerAttributeForAutoconfiguration(JsonStreamable::class, static function (ChildDefinition $definition, JsonStreamable $attribute) {
$definition->addExcludeTag('json_streamer.streamable', [
Expand Down
2 changes: 1 addition & 1 deletion src/Symfony/Bundle/FrameworkBundle/composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"ext-xml": "*",
"symfony/cache": "^6.4|^7.0",
"symfony/config": "^7.3",
"symfony/dependency-injection": "^7.2",
"symfony/dependency-injection": "^7.3",
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

addExcludeTag was added in version 7.3 by #59704

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternative to #59999

"symfony/deprecation-contracts": "^2.5|^3",
"symfony/error-handler": "^7.3",
"symfony/event-dispatcher": "^6.4|^7.0",
Expand Down
Loading