Doctrinebundle: Fatal Error: auto_generate_proxy_classes default value

Created on 18 Jan 2018  路  10Comments  路  Source: doctrine/DoctrineBundle

Hi,
After composer update, I got Fatal Error caused by doctrine which don't find proxy classes on prod mode.

I had the following configuration with Symfony 4 and Flex lastest version:

doctrine:
    dbal:
        # configure these for your database server
        driver: 'pdo_mysql'
        server_version: '5.7'
        charset: utf8mb4

        # With Symfony 3.3, remove the `resolve:` prefix
        url: '%env(resolve:DATABASE_URL)%'
    orm:
        auto_generate_proxy_classes: '%kernel.debug%'
        naming_strategy: doctrine.orm.naming_strategy.underscore
        auto_mapping: true
        mappings:
            App:
                is_bundle: false
                type: annotation
                dir: '%kernel.project_dir%/src/Entity'
                prefix: 'App\Entity'
                alias: App

After an update, I got the following error:

2018-01-18T18:46:02.385271+00:00 app[web.1]: [2018-01-18 18:46:02] php.WARNING: Warning: require(/app/var/cache/prod/doctrine/orm/Proxies/__CG__AppEntityProfile.php): failed to open stream: No such file or directory {"exception":"[object] (ErrorException(code: 0): Warning: require(/app/var/cache/prod/doctrine/orm/Proxies/__CG__AppEntityProfile.php): failed to open stream: No such file or directory at /app/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:223)"} []
2018-01-18T18:46:02.386436+00:00 app[web.1]: [2018-01-18 18:46:02] php.CRITICAL: Fatal Compile Error: require(): Failed opening required '/app/var/cache/prod/doctrine/orm/Proxies/__CG__AppEntityProfile.php' (include_path='.:/app/.heroku/php/lib/php') {"exception":"[object] (Symfony\\Component\\Debug\\Exception\\FatalErrorException(code: 0): Compile Error: require(): Failed opening required '/app/var/cache/prod/doctrine/orm/Proxies/__CG__AppEntityProfile.php' (include_path='.:/app/.heroku/php/lib/php') at /app/vendor/doctrine/common/lib/Doctrine/Common/Proxy/AbstractProxyFactory.php:223)"} []

I switch the value of auto_generate_proxy_classes to true and don't get any errors.

It seems legit that I had an error with auto_generate_proxy_classes: '%kernel.debug%' (false in prod mode) but I can't figure out why it works before the update.

Most helpful comment

Update composer.json with:

"scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "cache:warmup": "symfony-cmd"
        }
}

That should solve the issue.

All 10 comments

Try this again on the latest Symfony version - 4.0.4 - this looks like a container issue that was fixed.

I am having this same issue. Even after update to 4.0.4

setting auto_generate_proxy_classes: true fixes the issue.

As a follow up. Using the default '%kernel.debug%' (false in prod) works if you manually call
cache:warmup --env-prod
but
cache:clear --env-prod
Does not work. It was my understanding that trusting the cache:clear command to warm up the cache was accepted again based on the update to this blog. https://symfony.com/blog/new-in-symfony-3-3-deprecated-cache-clear-with-warmup

Ah yes. Indeed. This seems like a docs issue. On Symfony 4: you must use cache:clear and cache:warmup when you deploy. The warmup is needed because it generates your proxies. In sf3, cache:clear did this.

Can you open an issue on the Symfony docs so we can make sure this is clear?

Update composer.json with:

"scripts": {
        "auto-scripts": {
            "cache:clear": "symfony-cmd",
            "cache:warmup": "symfony-cmd"
        }
}

That should solve the issue.

It seems that https://github.com/symfony/symfony/issues/26219 notes the same behaviour.

I was having the same issue, and adding the cache:warmup command in the deployment scripts fixes it (SF4 v4.0.5)

This was eventually fixed by https://github.com/symfony/symfony/pull/26662. Closing here.

Hello, I'm having the same issue with SF 4.4 and ODM 2. I'm using capistrano/symfony for the deployment which run cach:warmup --no-debug. I even run the command manually in the server after deployment but nothing works so I had to set auto_generate_proxy_classes to true.

I just implemented a custom (very basic) CacheWarmerInterface and I'm getting the same error.

I don't want to ever set auto_generate_proxy_classes to true in production.

I am on 4.4.8.

Was this page helpful?
0 / 5 - 0 ratings