Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[DoctrineBridge] Error on UniqueEntityValidator with Mongodb and Doctrine #40057

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

Closed
FabienSalles opened this issue Feb 1, 2021 · 1 comment · Fixed by #40060
Closed

[DoctrineBridge] Error on UniqueEntityValidator with Mongodb and Doctrine #40057

FabienSalles opened this issue Feb 1, 2021 · 1 comment · Fixed by #40060

Comments

@FabienSalles
Copy link
Contributor

FabienSalles commented Feb 1, 2021

Symfony version used: 4.4.18
doctrine/mongodb-odm version used: 2.1.2
doctrine/mongodb-odm-bundle version used : 4.2.2

Description
When we use the UniqueEntity validator of Symfony by the Unique constraint of the doctrine bundle with a repository method that return an Iterator (in my case an instance of Doctrine\ODM\MongoDB\Iterator\CachingIterator which implement \Iterator interface), Symfony does not use correctly the iterator.

An empty result arrive to this line. The current() method return false instead of null so we end up with the result [false] and the error message is created.

I tested the use case on a old version of Symfony (3.3) and doctrine (1.2.9 for the ODM and 3.5.3 for the bundle), Doctrine return a instance of Doctrine\ODM\MongoDB\Cursor class wich return null on the method current()

How to reproduce
Add an Doctrine\Bundle\MongoDBBundle\Validator\Constraints\Unique constraint with a repository method that return an Iterator (for example with the execute() method of the QueryBuilder) and use the validator with an empty result.

Possible Solution
Check also if the Iterator is valid like this :

 $result = $result->valid() && null !== $result->current() ? [$result->current()] : [];
@xabbuh
Copy link
Member

xabbuh commented Feb 1, 2021

The proposed solution looks good to me. Can you send a pull request?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants