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

Lock exception leaves document with bad revision #1592

Conversation

mlodick
Copy link
Contributor

@mlodick mlodick commented May 16, 2017

A document's local version should only be incremented when the database version is, otherwise, if the lock exception is caught, a second persist & can succeed and overwrite data.

@alcaeus
Copy link
Member

alcaeus commented May 16, 2017

Changes look good, can you create a test for this use-case? Thanks!

Copy link
Member

@malarzm malarzm left a comment

Choose a reason for hiding this comment

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

Beside missing test please apply my remarks :)

@@ -426,6 +425,8 @@ public function update($document, array $options = array())

if (($this->class->isVersioned || $this->class->isLockable) && ! $result['n']) {
throw LockException::lockFailed($document);
} else if ($this->class->isVersioned && $nextVersion) {
Copy link
Member

Choose a reason for hiding this comment

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

We tend to keep elseif written together. Also If the class is versioned the $nextVersion must be present so there's no need for checking it here (the latter may not be true by looking only at if statements you've modifed above but that's validated on class metadata level)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fair enough.

@malarzm
Copy link
Member

malarzm commented May 29, 2017

@mlodick any chance you could write a test for the change you've implemented?

@mlodick
Copy link
Contributor Author

mlodick commented May 31, 2017

@malarzm sorry, I've been out of town. I'll get a test written today or tomorrow

@malarzm malarzm added this to the 1.1.6 milestone Jun 13, 2017
@alcaeus
Copy link
Member

alcaeus commented Aug 11, 2017

@mlodick could you add that test? I'd like to get this merged next week so we can release it in 1.1.6, otherwise I'd have to push it back to 1.1.7.

@mlodick
Copy link
Contributor Author

mlodick commented Aug 15, 2017

@alcaeus are these tests ok?

@alcaeus
Copy link
Member

alcaeus commented Aug 16, 2017

@mlodick I'll take a look tonight and update them myself if necessary. Thank you very much! ❤️

@alcaeus alcaeus self-requested a review August 16, 2017 18:51
Copy link
Member

@alcaeus alcaeus left a comment

Choose a reason for hiding this comment

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

Minor feedback on tests. Could you squash commits once you've fixed the issues? It's good to merge after that.

$class = DocumentPersisterTestDocumentWithVersion::class;
$documentPersister = $this->uow->getDocumentPersister($class);

$collection = $this->createMock('\MongoCollection');
Copy link
Member

Choose a reason for hiding this comment

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

You can use MongoCollection::class

$testDocument = new $class();
$testDocument->id = 12345;
$this->uow->registerManaged($testDocument, 12345, array('id' => 12345));
$this->setExpectedException('\Doctrine\ODM\MongoDB\LockException');
Copy link
Member

Choose a reason for hiding this comment

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

::class

$class = DocumentPersisterTestDocumentWithVersion::class;
$documentPersister = $this->uow->getDocumentPersister($class);

$collection = $this->createMock('\MongoCollection');
Copy link
Member

Choose a reason for hiding this comment

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

::class

@mlodick mlodick force-pushed the lock-exception-leaves-document-with-bad-revision branch from 8749043 to 588fc3d Compare August 16, 2017 19:07
@mlodick
Copy link
Contributor Author

mlodick commented Aug 16, 2017

@alcaeus I think this is all set then, though I'm not sure how to retrigger the test that failed - seems to have failed getting a pecl package.

@malarzm
Copy link
Member

malarzm commented Aug 16, 2017

@mlodick just restarted the job, let's see how it ends :)

@malarzm
Copy link
Member

malarzm commented Aug 16, 2017

Green it is, thanks @mlodick!

@malarzm malarzm merged commit 0c12d42 into doctrine:master Aug 16, 2017
@mlodick
Copy link
Contributor Author

mlodick commented Aug 16, 2017

👍 thank you

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