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

[Mapping] Fix inherited classes metadata collection #2651

Conversation

magikid
Copy link
Contributor

@magikid magikid commented Jul 20, 2023

All the work here was done by @gaelreyrol, I'm just opening the PR.

Fixes #2600

@gaelreyrol
Copy link
Contributor

gaelreyrol commented Jul 20, 2023

Hmm, I was waiting for @phansys feedback on the related issue to submit a PR, I do not want to put pressure on the maintainers of this repository even tho the fix is ready.

CHANGELOG.md Outdated
@@ -45,6 +45,7 @@ a release.
- Loggable: Remove unfixable deprecation when extending `LoggableListener`
- Remove unfixable deprecations when extending repository classes
- Fix error caused by the attempt of "doctrine/annotations" parsing a `@note` annotation
- Fix bug collecting metadata for inherited mapped classes

Choose a reason for hiding this comment

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

@magikid This should go under Unreleased , currently it's under [3.11.1] - 2023-02-20 which is wrong.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, sorry, I was confused because there weren't any of the subheadings in the Unreleased section.

@@ -114,7 +114,7 @@ public function getExtensionMetadata($meta)
if (null !== $meta->reflClass) {
foreach (array_reverse(class_parents($meta->getName())) as $parentClass) {
// read only inherited mapped classes
if ($cmf->hasMetadataFor($parentClass)) {
if ($cmf->hasMetadataFor($parentClass) || !$cmf->isTransient($parentClass)) {
Copy link
Collaborator

@franmomu franmomu Jul 24, 2023

Choose a reason for hiding this comment

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

I'm wondering if the $cmf->hasMetadataFor($parentClass) || part is necessary since it's confusing what it does and is not reliable.

Choose a reason for hiding this comment

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

IMO it can stay as is because the hasMetadataFor call is doing just an isset check under the hood while the isTransient call is more expensive since it goes to the mapping driver which then has to check whether the class with the specified name should have its metadata loaded or not (for example in the case of the atrribute driver it has to use reflection to check whether the class is mapped as an entity or as a mapped super class or neither).

Copy link
Collaborator

Choose a reason for hiding this comment

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

yeah, I guess it would save some calls to the driver, looking at the implementation of getParentClasses, they only use isTransient 🤔 :
https://github.com/doctrine/persistence/blob/413eb71a22c31c309b5a1cea9701d723cc0d4ae2/src/Persistence/Mapping/AbstractClassMetadataFactory.php#L278-L292

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From what I'm reading, I'll leave this as-is.

@phansys phansys added the Bug A confirmed bug in Extensions that needs fixing. label Jul 24, 2023
@codecov-commenter
Copy link

codecov-commenter commented Jul 24, 2023

Codecov Report

Patch coverage: 100.00% and no project coverage change.

Comparison is base (4fd6a62) 79.22% compared to head (c3027bc) 79.22%.

Additional details and impacted files
@@           Coverage Diff           @@
##             main    #2651   +/-   ##
=======================================
  Coverage   79.22%   79.22%           
=======================================
  Files         161      161           
  Lines        8415     8415           
=======================================
  Hits         6667     6667           
  Misses       1748     1748           
Files Changed Coverage Δ
src/Mapping/ExtensionMetadataFactory.php 83.13% <100.00%> (ø)

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@BacLuc
Copy link

BacLuc commented Aug 5, 2023

I tested it with the bug that appeared in https://github.com/ecamp/ecamp3
ecamp/ecamp3#3662
And it worked, thank you for the fix.

@solverat
Copy link

solverat commented Aug 8, 2023

Any updates on this? This PR also successfully fixes a lot of issues on our site.

@franmomu
Copy link
Collaborator

@magikid can you please rebase? I've tried but I couldn't because of permissions 😞

@franmomu franmomu requested a review from phansys August 14, 2023 11:34
@tristanbes
Copy link
Contributor

Just figuring out this bug after hours trying to understand why my timestamps were no longer applied. Thought it was because of doctrine 2.16 (doctrine/orm#10869) but in fact it was this issue.

Using a timestampable trait on an Abstract entity + prod mode = boom SQLSTATE Exception

Thanks for your PR @magikid

@magikid magikid force-pushed the fix-inherited-classes-metadata-collection branch from 113ebec to 8e8aa9e Compare August 15, 2023 17:34
@magikid magikid force-pushed the fix-inherited-classes-metadata-collection branch from 8e8aa9e to c53d200 Compare August 15, 2023 17:36
@magikid
Copy link
Contributor Author

magikid commented Aug 15, 2023

@franmomu I just rebased it

@franmomu
Copy link
Collaborator

Thanks, if you can fix the coding standard issues shown in https://github.com/doctrine-extensions/DoctrineExtensions/actions/runs/5869991947/job/15916135479?pr=2651 that would be all I think

@franmomu franmomu merged commit 351caed into doctrine-extensions:main Aug 19, 2023
20 checks passed
@franmomu
Copy link
Collaborator

Thanks @gaelreyrol and @magikid!

@yakobe
Copy link

yakobe commented Sep 6, 2023

@phansys Would it be possible to get a release with this included? Thanks everyone for helping to solve this 😸 !

@phansys
Copy link
Collaborator

phansys commented Sep 6, 2023

Sure! 3.13.0.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug A confirmed bug in Extensions that needs fixing.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Mapping] Metadata for inherited mapped classes are not well collected
10 participants