This article provides a fix when on Magento Commerce (Cloud) you receive an error when the application accesses the var/generation
directory. This might occur die to a missing constructor dependency injection. As an immediate workaround, you may turn off the symlink generation via this deployment variable:
GENERATED_CODE_SYMLINK = disabled
The build variable GENERATED_CODE_SYMLINK
was removed for Magento Commerce (Cloud) 2.2 and later.
Affected versions
Magento Commerce Cloud 2.0.X, 2.1.X
Issue
When the Magento application tries to access resources, located in the var/generation
directory, errors like the following ones might occur:
"/app/var/generation/<path/to/resource>" file could not be written Warning!file_put_contents(/app/var/generation/<path/to/resource>): failed to open stream: Read-only file system in /app/vendor/magento/<path/to/resource>
The file "/app/var/generation/<path/to/resource>" cannot be deleted Warning!unlink(/app/var/generation/<path/to/resource>): Read-only file system
Cause
The problem occurs when the constructor dependency injection has not been implemented for an optional or required dependency of the affected object. In this case, Magento tries to generate the missing constructor dependencies on the fly, which causes an error because the var/generation directory is read-only during runtime.
Possible solution
As an immediate fix, you may change the flow of deployment process by disabling the symlink generation using the following environment variable:
GENERATED_CODE_SYMLINK = disabled
In this case, the generated objects are being copied directly to the destination directory instead of being symlinked. Thus, Magento can successfully generate objects on the fly.
Turning off symlink generation may increase the potential downtime of your environment during deployment.
Permissions to change variables on Development, Staging, and Production
You may set the environment variable yourself on the local and Integration (Development) environments.For Staging and Production environments, submit a support ticket requesting to change the variable.