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

[GH-7633] disallow cache partial objects #8050

Merged
merged 4 commits into from Mar 15, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/Doctrine/ORM/Cache/DefaultQueryCache.php
Expand Up @@ -260,7 +260,7 @@ public function put(QueryCacheKey $key, ResultSetMapping $rsm, $result, array $h
throw new CacheException("Second-level cache query supports only select statements.");
}

if (isset($hints[Query\SqlWalker::HINT_PARTIAL]) && $hints[Query\SqlWalker::HINT_PARTIAL]) {
if (($hints[Query\SqlWalker::HINT_PARTIAL] ?? false) === true || ($hints[Query::HINT_FORCE_PARTIAL_LOAD] ?? false) === true) {
Copy link
Member

Choose a reason for hiding this comment

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

Then we can do this:

Suggested change
if (($hints[Query\SqlWalker::HINT_PARTIAL] ?? false) === true || ($hints[Query::HINT_FORCE_PARTIAL_LOAD] ?? false) === true) {
if (($hints[Query\SqlWalker::HINT_PARTIAL] ?? $hints[Query::HINT_FORCE_PARTIAL_LOAD] ?? false) === true) {

Copy link
Member Author

Choose a reason for hiding this comment

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

I like to keep it this way now.

throw new CacheException("Second level cache does not support partial entities.");
}

Expand Down
Expand Up @@ -1099,6 +1099,21 @@ public function testCacheablePartialQueryException()
->getResult();
}

/**
* @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second level cache does not support partial entities.
*/
public function testCacheableForcePartialLoadHintQueryException()
{
$this->evictRegions();
$this->loadFixturesCountries();

$this->_em->createQuery("SELECT c FROM Doctrine\Tests\Models\Cache\Country c")
->setCacheable(true)
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->getResult();
}
Copy link
Member

@lcobucci lcobucci Mar 2, 2020

Choose a reason for hiding this comment

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

@expectedException and @expectedExceptionMessage have been deprecated in PHPUnit 8.x and removed in PHPUnit v9.0. We should avoid using them.

We might need to import Doctrine\ORM\Cache\CacheException but this should be the way to go:

Suggested change
/**
* @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second level cache does not support partial entities.
*/
public function testCacheableForcePartialLoadHintQueryException()
{
$this->evictRegions();
$this->loadFixturesCountries();
$this->_em->createQuery("SELECT c FROM Doctrine\Tests\Models\Cache\Country c")
->setCacheable(true)
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->getResult();
}
public function testCacheableForcePartialLoadHintQueryException()
{
$this->evictRegions();
$this->loadFixturesCountries();
$this->expectException(CacheException::class);
$this->expectExceptionMessage('Second level cache does not support partial entities.');
$this->_em->createQuery("SELECT c FROM Doctrine\Tests\Models\Cache\Country c")
->setCacheable(true)
->setHint(Query::HINT_FORCE_PARTIAL_LOAD, true)
->getResult();
}

Copy link
Member Author

Choose a reason for hiding this comment

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

99 occurrences of this in tests on 2.7, i move this to a mainteance task for 2.8


/**
* @expectedException \Doctrine\ORM\Cache\CacheException
* @expectedExceptionMessage Second-level cache query supports only select statements.
Expand Down