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

#6217 when hydrating an entity with a composite primary key that is both an EAGER and a LAZY association and also cached, the DefaultQueryCache tries to pass L2 cache implementation detail objects to the UnitOfWork #6284

Closed
wants to merge 1 commit into from

Conversation

gadelkareem
Copy link
Contributor

I recreated the branch for #6217 which forced closing to PR so I am submitting this as a new PR.

DESC: Handle AssociationCacheEntry identifier

Fixes Notice: Undefined property: Doctrine\ORM\Cache\AssociationCacheEntry::$id when retrieving an associated entity from a Composite primary key

@Ocramius
Copy link
Member

@lcobucci if you merge this one, can you please check if the test can be moved to a smaller SUT test?

@lcobucci lcobucci force-pushed the patch-1 branch 3 times, most recently from 6731689 to 7509c16 Compare February 19, 2017 10:48
Copy link
Member

@lcobucci lcobucci left a comment

Choose a reason for hiding this comment

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

@gadelkareem thanks for the patch!

@Ocramius I've managed to reduce the SUT and saw that the problem ONLY happens when the fetch mode is EAGER.

I've rebased it, removed some unrelated CS fixes and applied the same logic here.

@Ocramius although it LGTM would be nice to have your eyes too

@lcobucci lcobucci assigned Ocramius and unassigned lcobucci Feb 20, 2017
Copy link
Member

@Ocramius Ocramius left a comment

Choose a reason for hiding this comment

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

Ouch, forgot to send in this review :-\

@@ -738,6 +739,15 @@ public function getIdentifierValues($entity)
return [$id => $value];
}

private function getIndentifierValue($entity, $id)
Copy link
Member

Choose a reason for hiding this comment

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

Docblock needed. id probably needs a type-hint too, if we target 2.6 only

Copy link
Member

Choose a reason for hiding this comment

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

The fact that $entity can both be an entity and a cache entry is quite bothersome... Why was this choice made?

* @Entity
* @Cache(usage="NONSTRICT_READ_WRITE")
*/
class GH6217UserProfile
Copy link
Member

Choose a reason for hiding this comment

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

Could you rename this to something like GH6217EntityWith3IdentityFieldsThroughAssociation or such? I think that expresses intent much better. (yes, if you have a better name, please use that :-))

Same applies to the other entities.

* @Id
* @Cache("NONSTRICT_READ_WRITE")
* @ManyToOne(targetEntity="GH6217Profile", fetch="EAGER")
*
Copy link
Member

Choose a reason for hiding this comment

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

No join column here?

* @Id
* @Cache("NONSTRICT_READ_WRITE")
* @ManyToOne(targetEntity="GH6217Category", fetch="EAGER")
*
Copy link
Member

Choose a reason for hiding this comment

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

No join column here?

@@ -0,0 +1,162 @@
<?php
namespace Doctrine\Tests\Functional\Ticket;
Copy link
Member

Choose a reason for hiding this comment

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

Can you add a strict types declaration, since you are being quite strict about API usage in the test?

@Ocramius
Copy link
Member

Re-iterating this: I don't think that classmetadata should ever interact with an AssociationCacheEntry object. This patch fixes a symptom, rather than the cause of the issue, which is the fact that an AssociationCacheEntry object is given to the metadata in first place.

@Ocramius
Copy link
Member

I checked this patch locally, and the bug is fixed on the wrong end here: the DefaultQueryCache is passing incorrect data to UnitOfWork#createEntity(). I'm currently fixing that 👍

@Ocramius Ocramius changed the title Add tests for #6217 #6217 when hydrating an entity with a composite primary key that is both an EAGER and a LAZY association and also cached, the DefaultQueryCache tries to pass L2 cache implementation detail objectsto the UnitOfWork Aug 22, 2017
@Ocramius Ocramius changed the title #6217 when hydrating an entity with a composite primary key that is both an EAGER and a LAZY association and also cached, the DefaultQueryCache tries to pass L2 cache implementation detail objectsto the UnitOfWork #6217 when hydrating an entity with a composite primary key that is both an EAGER and a LAZY association and also cached, the DefaultQueryCache tries to pass L2 cache implementation detail objects to the UnitOfWork Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
Ocramius added a commit that referenced this pull request Aug 22, 2017
…ching issue.

We are not hydrating some of the cached association data into entities due to keys missing in the cache association definition.
Since this is an extreme edge case that is just a mismatch between db and cache, a detailed explanation was provided in the fix snippet as well
Ocramius added a commit that referenced this pull request Aug 22, 2017
…id fix that was actually fixing the symptom
@Ocramius
Copy link
Member

@gadelkareem please check #6640 and verify it against your codebase.

@gadelkareem
Copy link
Contributor Author

@Ocramius thanks for the fix and sorry for having no time to help
All tests are passing including GH6217Test so I think this is fixed.

Ocramius added a commit that referenced this pull request Aug 25, 2017
…l2-cache-information-internals-to-the-uow

#6217 #6284 when hydrating an entity with a composite primary key that is both an `EAGER` and a `LAZY` association and also cached, the `DefaultQueryCache` tries to pass L2 cache implementation detail objects to the `UnitOfWork`
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants