Skip to content
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

[GH-8229] Prevent Illegal Inheritance Override #8348

Merged
merged 10 commits into from
Nov 25, 2020

Conversation

beberlei
Copy link
Member

@beberlei beberlei commented Nov 24, 2020

The PRs #8234 and #8329 are based on a flawed understanding of inheritance in Doctrine and need to be reverted:

One excemption was made to use @AssocationOVerride only for changing the fetch strategy. Soft-deprecated this with a TODO.

While Doctrine so far allowed these things, they are fragile and will break on certain scenarios. Please give feedback here or in new issues on the impact of this change on your projects.

@beberlei beberlei requested a review from ostrolucky November 24, 2020 17:24
@beberlei beberlei requested a review from greg0ire November 24, 2020 19:18
// TODO: Deprecate overriding the fetch mode via association override for 3.0,
// users should do this with a listener and a custom attribute/annotation
throw MappingException::illegalOverrideOfInheritedProperty($this->name, $fieldName);
}
Copy link
Member

Choose a reason for hiding this comment

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

Should the parts that are about throwing be contributed to 2.8 instead? If we think there are people currently using this, we should probably not have it blow up in their face in a patch

Copy link
Member Author

Choose a reason for hiding this comment

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

You are right, i should remove them for 2.7, and re-introduce them for 2.8

greg0ire
greg0ire previously approved these changes Nov 25, 2020
@beberlei beberlei merged commit 404edd4 into doctrine:2.7 Nov 25, 2020
@beberlei beberlei deleted the GH-8229-InheritenceFixes branch November 25, 2020 22:05
@beberlei beberlei added this to the 2.7.5 milestone Dec 4, 2020
@Kalyse
Copy link

Kalyse commented Dec 19, 2020

Entities are not allowed to extend from entities without an inheritence mapping relationship (Single Table or Joined Table inheritance). If you have this use case you should instead have two entities and they each extend a common @MappedSuperclass.

I think this update just severely broke my application. I'm still debugging, however, I use a ClassMetadataSubscriber to override the [name] field on the Entities to match a prefix. ie. You know how wordpess prefixes based on wp_, I do similar.

Anyway, I have a MappedSuperclass called.. "Building", and then I have on entity which extends it, called "Room".

It appears now, as though the MappedSuperClass "Building" does not existing within the LoadClassMetadataEventArgs event passesd to my subscriber.

Is this intended? It loosk like all MapperSuperClasses have been removed, so any of my superclasses now do not exist with the vendor prefix.

What ended up happening on my development machine was 20 table deletions.. so it's quite a big issue which I didn't expect from a minor patch?

@beberlei
Copy link
Member Author

Please open up a new issue and improve the issue description, I don't understand mapped superclasses do not have tables, and should not have table prefixes. What means "not existing within LoadClassMetadataEventArgs"?

@mpdude
Copy link
Contributor

mpdude commented Jan 19, 2023

#10431 suggests adding a runtime check for missing inheritance declarations

mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 20, 2023
Inheritance has to be declared as soon as one entity class extends (directly or through middle classes) another one.

This is also pointed out in the opening comment for doctrine#8348:

> Entities are not allowed to extend from entities without an inheritence mapping relationship (Single Table or Joined Table inheritance). [...] While Doctrine so far allowed these things, they are fragile and will break on certain scenarios.

Throwing an exception in case of this misconfiguration is nothing we should do light-heartedly, given that it may surprise users in a bugfix or feature release. So, we should start with a deprecation notice  and make this an exception in 3.0. The documentation is updated accordingly at doctrine#10429.

Catching missing inheritance declarations early on is important to avoid weird errors further down the road, giving users a clear indication of the root cause.

In case you are affected by this, please understand that although things "previously worked" for you, you have been using the ORM outside of what it was designed to do. That may have worked in simple cases, but may also have caused invalid results (wrong or missing data after hydration?) that possibly went unnoticed in subtle cases.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 23, 2023
Inheritance has to be declared as soon as one entity class extends (directly or through middle classes) another one.

This is also pointed out in the opening comment for doctrine#8348:

> Entities are not allowed to extend from entities without an inheritence mapping relationship (Single Table or Joined Table inheritance). [...] While Doctrine so far allowed these things, they are fragile and will break on certain scenarios.

Throwing an exception in case of this misconfiguration is nothing we should do light-heartedly, given that it may surprise users in a bugfix or feature release. So, we should start with a deprecation notice  and make this an exception in 3.0. The documentation is updated accordingly at doctrine#10429.

Catching missing inheritance declarations early on is important to avoid weird errors further down the road, giving users a clear indication of the root cause.

In case you are affected by this, please understand that although things "previously worked" for you, you have been using the ORM outside of what it was designed to do. That may have worked in simple cases, but may also have caused invalid results (wrong or missing data after hydration?) that possibly went unnoticed in subtle cases.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 23, 2023
Inheritance has to be declared as soon as one entity class extends (directly or through middle classes) another one.

This is also pointed out in the opening comment for doctrine#8348:

> Entities are not allowed to extend from entities without an inheritence mapping relationship (Single Table or Joined Table inheritance). [...] While Doctrine so far allowed these things, they are fragile and will break on certain scenarios.

Throwing an exception in case of this misconfiguration is nothing we should do light-heartedly, given that it may surprise users in a bugfix or feature release. So, we should start with a deprecation notice  and make this an exception in 3.0. The documentation is updated accordingly at doctrine#10429.

Catching missing inheritance declarations early on is important to avoid weird errors further down the road, giving users a clear indication of the root cause.

In case you are affected by this, please understand that although things "previously worked" for you, you have been using the ORM outside of what it was designed to do. That may have worked in simple cases, but may also have caused invalid results (wrong or missing data after hydration?) that possibly went unnoticed in subtle cases.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 24, 2023
Inheritance has to be declared as soon as one entity class extends (directly or through middle classes) another one.

This is also pointed out in the opening comment for doctrine#8348:

> Entities are not allowed to extend from entities without an inheritence mapping relationship (Single Table or Joined Table inheritance). [...] While Doctrine so far allowed these things, they are fragile and will break on certain scenarios.

Throwing an exception in case of this misconfiguration is nothing we should do light-heartedly, given that it may surprise users in a bugfix or feature release. So, we should start with a deprecation notice  and make this an exception in 3.0. The documentation is updated accordingly at doctrine#10429.

Catching missing inheritance declarations early on is important to avoid weird errors further down the road, giving users a clear indication of the root cause.

In case you are affected by this, please understand that although things "previously worked" for you, you have been using the ORM outside of what it was designed to do. That may have worked in simple cases, but may also have caused invalid results (wrong or missing data after hydration?) that possibly went unnoticed in subtle cases.
derrabus pushed a commit that referenced this pull request Jan 24, 2023
Inheritance has to be declared as soon as one entity class extends (directly or through middle classes) another one.

This is also pointed out in the opening comment for #8348:

> Entities are not allowed to extend from entities without an inheritence mapping relationship (Single Table or Joined Table inheritance). [...] While Doctrine so far allowed these things, they are fragile and will break on certain scenarios.

Throwing an exception in case of this misconfiguration is nothing we should do light-heartedly, given that it may surprise users in a bugfix or feature release. So, we should start with a deprecation notice  and make this an exception in 3.0. The documentation is updated accordingly at #10429.

Catching missing inheritance declarations early on is important to avoid weird errors further down the road, giving users a clear indication of the root cause.

In case you are affected by this, please understand that although things "previously worked" for you, you have been using the ORM outside of what it was designed to do. That may have worked in simple cases, but may also have caused invalid results (wrong or missing data after hydration?) that possibly went unnoticed in subtle cases.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 26, 2023
…ridden

This was brought up in doctrine#8348, but seemingly forgotten to be implenented in later versions.

Closes doctrine#10289.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Feb 9, 2023
…ridden

This was brought up in doctrine#8348, but seemingly forgotten to be implenented in later versions.

Closes doctrine#10289.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants