DoctrineExtensions: TranslationWalker does not run when Query Cache is enabled

I had a bug with translatable, it was firing queries even though registering the walker and hinting the right locale was done properly. After tracing the problem i came to the conclusion that Query Caching should be disabled for queries using Translatable. To disable the query cache on a query: $query->useQueryCache(false);

Reasoning: If query cache is used the Parser is never invoked: https://github.com/doctrine/doctrine2/blob/5c44dd38234f2e143e376ac94d2e7f945d7f9328/lib/Doctrine/ORM/Query.php#L248

If the Parser does not run then no custom output walkers are checked: https://github.com/doctrine/doctrine2/blob/4f585a3d6372ef1115a30663fe0005f611decd76/lib/Doctrine/ORM/Query/Parser.php#L357

I think the difference between a HINT_CUSTOM_TREE_WALKERS (SQL Walker) and HINT_CUSTOM_OUTPUT_WALKER (output walker) is that the first changes the actual DQL query and the latter always has to be done afterwards.

This is possibly a limitation of Doctrine

To do: gedmo translatable should automatically turn off query caching when it needs to register an output walker

About this issue

  • Original URL
  • State: closed
  • Created 13 years ago
  • Comments: 19 (6 by maintainers)

Commits related to this issue

Most upvoted comments

Just stumbled across this problem using Doctrine ORM version v2.5.4 and DoctrineExtensions v2.4.1. Sadly took me 4h to find out I had to add this one liner :

$query->useQueryCache(false);

I was querying the ORM with translations (using StofDoctrineExtensions) where the request locale was not the same as the locale in the query hint. The first query worked, the ones after that didn’t get the correct translation (they defaulted to the request locale).

On all queries I used:

     $query->setHint(\Gedmo\Translatable\TranslatableListener::HINT_TRANSLATABLE_LOCALE, $locale);
     $query->setHint(
                \Doctrine\ORM\Query::HINT_CUSTOM_OUTPUT_WALKER,
                'Gedmo\\Translatable\\Query\\TreeWalker\\TranslationWalker'
            );