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

Skip to content

[DoctrineBridge][Form] Fix BC break in DoctrineType #14576

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
wants to merge 2 commits into from

Conversation

malarzm
Copy link
Contributor

@malarzm malarzm commented May 7, 2015

Q A
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets #14568
License MIT
Doc PR n/a

@malarzm malarzm changed the title [DoctrineBridge][Form] Fix BC break in QueryBuilder normalizer [DoctrineBridge][Form] Remove BC break in QueryBuilder normalizer May 7, 2015
@plozmun
Copy link
Contributor

plozmun commented May 7, 2015

I have test this with Doctrine/Mongo and i found next error:

Attempted to call an undefined method named "getSQL" of class "Doctrine\ODM\MongoDB\Query\Query".
in vendor/symfony/symfony/src/Symfony/Bridge/Doctrine/Form/Type/DoctrineType.php at line 127   -

Removing $qbParts and its references it works

                $hash = CachingFactoryDecorator::generateHash(array(
                    $options['em'],
                    $options['class'],
                    $options['loader'],
                ));

@malarzm malarzm changed the title [DoctrineBridge][Form] Remove BC break in QueryBuilder normalizer [DoctrineBridge][Form] Remove BC break in DoctrineType May 7, 2015
@malarzm
Copy link
Contributor Author

malarzm commented May 7, 2015

@arkadis I've added check if query builder is indeed one from ORM

@plozmun
Copy link
Contributor

plozmun commented May 7, 2015

Now it works perfectly! Thanks!

@Tobion
Copy link
Contributor

Tobion commented May 7, 2015

The allowed types for query builder should then be set on the subclass (entity)

@malarzm
Copy link
Contributor Author

malarzm commented May 7, 2015

@Tobion in fact you're right, I will move code I have removed to Entity type

@malarzm malarzm changed the title [DoctrineBridge][Form] Remove BC break in DoctrineType [DoctrineBridge][Form] Fix BC break in DoctrineType May 7, 2015
@malarzm
Copy link
Contributor Author

malarzm commented May 7, 2015

@Tobion done, commits are squashed, travis is green

@nicolas-grekas
Copy link
Member

Would it possible to add a test to prevent any regression?

@malarzm
Copy link
Contributor Author

malarzm commented May 13, 2015

@nicolas-grekas what do you think about creating new Type for tests that won't override any options, pass some class as query_builder (both object and closure returning it) and expect that exception will not be thrown?

@@ -124,7 +122,7 @@ public function configureOptions(OptionsResolver $resolver)
if (null === $options['choices']) {
// We consider two query builders with an equal SQL string and
// equal parameters to be equal
$qbParts = $options['query_builder']
$qbParts = $options['query_builder'] instanceof \Doctrine\ORM\QueryBuilder
? array(
$options['query_builder']->getQuery()->getSQL(),
$options['query_builder']->getParameters()->toArray(),
Copy link
Member

Choose a reason for hiding this comment

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

This logic to compare the query builder is specific to the ORM, so it must go in the child class, with a way for other Doctrine implementations (in MongoDBBundle for instance) to provide their own hashing for their query builders.

and in case the query builder cannot be compared (MongoDBBundle not implementing the method yet), the cache should be avoided instead of using the wrong cache.

@malarzm
Copy link
Contributor Author

malarzm commented May 14, 2015

@stof I have changed the caching logic, can you take a look?

* @internal This method is public to be usable as callback. It should not
* be used in user code.
*/
public function getQueryBuilderPartsForCachingHash($queryBuilder)
Copy link
Member

Choose a reason for hiding this comment

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

protected would work isn't it ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It yells that it has to be public as that's how parent class defines it

Copy link
Member

Choose a reason for hiding this comment

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

changing the parent is also possible

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Won't it break in PHP 5.3?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

please try moving both of them to protected. It should work, and anyway tests will tell if I'm wrong on 5.3 or any other version

@malarzm
Copy link
Contributor Author

malarzm commented May 15, 2015

@nicolas-grekas https://travis-ci.org/symfony/symfony/jobs/62702058#L1706 - I'm going to throw out last commit

* @return array|false Array with important QueryBuilder parts or false if
* they can't be determined
*/
protected function getQueryBuilderPartsForCachingHash($queryBuilder)
Copy link
Member

Choose a reason for hiding this comment

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

my bad, I missed the closure... public required sorry

@malarzm
Copy link
Contributor Author

malarzm commented May 15, 2015

Ok, so last Travis fail is unrelated to my changes :)

@fabpot
Copy link
Member

fabpot commented May 20, 2015

Thank you @malarzm.

@fabpot fabpot closed this in 2213e67 May 20, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants