Skip to content

Fix/1497 #1498

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 2 commits into from
Sep 27, 2016
Merged

Fix/1497 #1498

merged 2 commits into from
Sep 27, 2016

Conversation

akomm
Copy link
Contributor

@akomm akomm commented Sep 27, 2016

Failing test (1. commit) and fix (2. commit)

@alcaeus
Copy link
Member

alcaeus commented Sep 27, 2016

Thanks for the PR! Since this bug is already present in 1.1.x, it needs to target the 1.1.x branch, not master. I could change the target branch of the PR, but due to the different branch ancestor the PR wouldn't come out clean. You can either create a new PR based on the 1.0.x branch or manually reset your branch to 1.1.x before re-applying the commits and then force-pushing to the branch, after which we can change the target branch of the PR. If this is too complicated, you can also enable this checkbox in the PR sidebar and I'll update the branch for you:
image

Edit: this needs a separate PR for 1.0.x due to the migration from PersistentCollection to PersistentCollectionTrait with 1.0.0. I can apply changes after merging.

@alcaeus alcaeus added this to the 1.0.8 milestone Sep 27, 2016
@alcaeus alcaeus added the Bug label Sep 27, 2016
@@ -540,6 +540,7 @@ public function clear()
}

if ($this->isOrphanRemovalEnabled()) {
$this->initialize();
Copy link
Contributor

@Steveb-p Steveb-p Sep 27, 2016

Choose a reason for hiding this comment

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

It still won't execute due to the $this->initialized you pointed out earlier. At first glance I would just remove $this->initialized from if, but I did not read further down the code to be sure.

I believe that if you're calling clear, then you want the collection to be cleared regardless if it was already initialized or not though.

Copy link
Member

Choose a reason for hiding this comment

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

If collection is not initialized then if statements will evaluate to false thus reaching this point

Copy link
Contributor

Choose a reason for hiding this comment

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

Damn, true ;)

Copy link
Contributor Author

@akomm akomm Sep 27, 2016

Choose a reason for hiding this comment

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

I'v made two commits so you can see the test failing and then not failing any more with the fix commit. In the bug-case $this->initialized is false, so the code after the if IS executed :). Removing the $this->initialized check & not inserting the $this->initialize() line cause the test to fail again. It looks like $this->isEmpty() is not (implicitly) triggering initialization either.

Copy link
Member

Choose a reason for hiding this comment

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

It looks like $this->isEmpty() is not (implicitly) triggering initialization either.

You are correct. isEmpty uses the count method defined in PersistentCollectionTrait if the collection is not initialized, which again does not initialize the collection (because it doesn't need to).

@akomm
Copy link
Contributor Author

akomm commented Sep 27, 2016

I'v reset & reapplied it from 1.1.x. I'v also made a PR from 1.0.x #1500

@alcaeus alcaeus changed the base branch from master to 1.1.x September 27, 2016 12:43
@alcaeus alcaeus modified the milestones: 1.1.2, 1.0.8 Sep 27, 2016
@alcaeus alcaeus merged commit cc982d7 into doctrine:1.1.x Sep 27, 2016
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.

4 participants