Skip to content

Throw an exception when passing an entity alias #295

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

Merged
merged 1 commit into from
May 5, 2022

Conversation

stof
Copy link
Member

@stof stof commented May 5, 2022

Many users have missed the deprecation about using an entity alias when they migrated to doctrine/persistence 3.
Passing an entity alias was triggering a weird error due to generating an invalid PSR-6 cache key due to : being a reserved keyword. So this adds a dedicated check reporting that it is an invalid class name instead.

@@ -389,6 +391,14 @@ public function isTransient(string $className)
$this->initialize();
}

if (class_exists($className, false) && (new ReflectionClass($className))->isAnonymous()) {
Copy link
Member

Choose a reason for hiding this comment

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

could this be on the hot path? strpos for @ should be enough to check for anonymous classes if yes

Copy link
Member Author

Choose a reason for hiding this comment

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

That's the same check than done in getMetadataFor already.

Many users have missed the deprecation about using an entity alias when
they migrated to doctrine/persistence 3.
Passing an entity alias was triggering a weird error due to generating
an invalid PSR-6 cache key due to `:` being a reserved keyword. So this
adds a dedicated check reporting that it is an invalid class name
instead.
@stof stof force-pushed the block_entity_alias branch from 2a2d098 to dbf1a09 Compare May 5, 2022 10:11
@malarzm malarzm added this to the 3.0.2 milestone May 5, 2022
@greg0ire
Copy link
Member

greg0ire commented May 5, 2022

Since this is an improvement, should it target 3.1.x?

@malarzm
Copy link
Member

malarzm commented May 5, 2022

Since this is an improvement, should it target 3.1.x?

It's not a feature though :) It's literally an improvement so breaking change introduced in 3.x is visible to endusers

@greg0ire
Copy link
Member

greg0ire commented May 5, 2022

To me, improvements and features are both minor changes; I don't think an improvement qualifies as a patch. Semver mentions "improvements" in the "minor" section also.

@stof
Copy link
Member Author

stof commented May 5, 2022

Well, I'm fine targetting 3.1.x if 3.1.0 is released soon. But I'd like for this error message to reach the users ASAP so that they stop reporting issues on Symfony saying that cache keys are invalid.

@greg0ire
Copy link
Member

greg0ire commented May 5, 2022

I don't see an issue with releasing it right after merging this. IMO we should try to stick with semver since we don't have constraints on our release schedule. Every time I break something as part of a patch release when it should have gone in a minor mine, there's always some user who makes sure to point that out.

@malarzm
Copy link
Member

malarzm commented May 5, 2022

We also have a bugfix to release and releasing both PRs as 3.0.2 sounds like less work that 3.0.2 and later 3.1.0 with just a friendly exception :) But that's just how I'd proceed (feel free to "blame me" if we do it this way), do as you feel is right :)

@greg0ire
Copy link
Member

greg0ire commented May 5, 2022

In the end, I agree that it's not a huge deal, and I take good note that you will be the scapegoat for this time 😜 Let's not make this more complicated that it needs to be.

@malarzm malarzm merged commit c126597 into doctrine:3.0.x May 5, 2022
@malarzm
Copy link
Member

malarzm commented May 5, 2022

Thanks @stof!

@stof stof deleted the block_entity_alias branch May 6, 2022 07:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

5 participants