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

Deprecate undeclared entity inheritance #10431

Merged
merged 1 commit into from
Jan 24, 2023

Conversation

mpdude
Copy link
Contributor

@mpdude mpdude commented Jan 19, 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.

Update: For one example of strange things that may happen down the road, see #3037 (comment).

@mpdude mpdude force-pushed the catch-wrong-hierarchies branch from 4c59207 to 2f476f4 Compare January 19, 2023 09:09
@mpdude mpdude changed the title Catch missing inheritance declarations early on Catch missing inheritance declarations early on (👀 👀 required!) Jan 19, 2023
@mpdude mpdude changed the title Catch missing inheritance declarations early on (👀 👀 required!) Catch missing inheritance declarations early on Jan 19, 2023
@mpdude mpdude changed the title Catch missing inheritance declarations early on Deprecate undeclared entity inheritance Jan 20, 2023
@mpdude mpdude force-pushed the catch-wrong-hierarchies branch 4 times, most recently from 118840a to da8601b Compare January 20, 2023 23:23
@derrabus
Copy link
Member

As always, we don't introduce deprecations in bugfix releases. Please target 2.15.

@mpdude mpdude force-pushed the catch-wrong-hierarchies branch from da8601b to 7d7dc1b Compare January 23, 2023 12:57
@mpdude mpdude changed the base branch from 2.14.x to 2.15.x January 23, 2023 12:57
@mpdude
Copy link
Contributor Author

mpdude commented Jan 23, 2023

Rebased onto 2.15.x, and tied a knot in my handkerchief.

@mpdude mpdude force-pushed the catch-wrong-hierarchies branch from 7d7dc1b to 835212f Compare January 23, 2023 12:59
UPGRADE.md Outdated Show resolved Hide resolved
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 mpdude force-pushed the catch-wrong-hierarchies branch from 835212f to 384a5b4 Compare January 24, 2023 20:51
@mpdude
Copy link
Contributor Author

mpdude commented Jan 24, 2023

Feedback addressed

@derrabus derrabus merged commit 6568782 into doctrine:2.15.x Jan 24, 2023
@derrabus
Copy link
Member

Thanks!

@mpdude mpdude deleted the catch-wrong-hierarchies branch January 24, 2023 22:04
@mpdude
Copy link
Contributor Author

mpdude commented Jan 24, 2023

💪🏻

Let’s hope it will not cause too much confusion and problems for users in 2.15.

Shall I create a dedicated PR to make the switch in 3.0? Requires changes to be merged up before, though.

derrabus added a commit to derrabus/orm that referenced this pull request Jan 26, 2023
* 2.15.x:
  Deprecate undeclared entity inheritance (doctrine#10431)
  Psalm 5.5.0 (doctrine#10445)
derrabus added a commit to derrabus/orm that referenced this pull request Jan 26, 2023
* 2.15.x:
  Deprecate undeclared entity inheritance (doctrine#10431)
  Psalm 5.5.0 (doctrine#10445)
derrabus added a commit to derrabus/orm that referenced this pull request Jan 26, 2023
* 2.15.x:
  Deprecate undeclared entity inheritance (doctrine#10431)
  Psalm 5.5.0 (doctrine#10445)
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 26, 2023
In doctrine#10431, some invalid inheritance declarations in our test base were fixed. However, the change missed to update XML, PHP and static PHP mapping configurations as well.

Apparently, this did not raise any flags because the misconfiguration only caused a deprecation notice in 2.15.x. Running the tests against 3.0 (where the misconfiguration will be an error) unveiled the mistake.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 26, 2023
This removes comments added in doctrine#10431 on the 2.15.x branch, as suggested in doctrine#10460 (comment).
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 26, 2023
This removes comments added in doctrine#10431 on the 2.15.x branch, as suggested in doctrine#10460 (comment).
derrabus pushed a commit that referenced this pull request Jan 26, 2023
This removes comments added in #10431 on the 2.15.x branch, as suggested in #10460 (comment).
derrabus pushed a commit that referenced this pull request Jan 26, 2023
In #10431, some invalid inheritance declarations in our test base were fixed. However, the change missed to update XML, PHP and static PHP mapping configurations as well.

Apparently, this did not raise any flags because the misconfiguration only caused a deprecation notice in 2.15.x. Running the tests against 3.0 (where the misconfiguration will be an error) unveiled the mistake.
derrabus added a commit to derrabus/orm that referenced this pull request Jan 27, 2023
* 2.15.x:
  Psalm 5.6.0, PHPStan 1.9.14 (doctrine#10468)
  Fix some tests that were missed in doctrine#10431 (doctrine#10464)
  Remove commented-out code sections (doctrine#10465)
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 27, 2023
This follows up on doctrine#10431: This kind of misconfiguration triggered a deprecation warning since 2.15.x. Now let's make it an exception.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 27, 2023
This follows up on doctrine#10431: This kind of misconfiguration triggered a deprecation warning since 2.15.x. Now let's make it an exception.
mpdude added a commit to mpdude/doctrine2 that referenced this pull request Jan 27, 2023
This follows up on doctrine#10431: This kind of misconfiguration triggered a deprecation warning since 2.15.x. Now let's make it an exception.
derrabus pushed a commit that referenced this pull request Feb 8, 2023
This follows up on #10431: This kind of misconfiguration triggered a deprecation warning since 2.15.x. Now let's make it an exception.
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.

2 participants