Orm: Warning: rename(...\var\cache\dev/doctrine/orm/Proxies\__CG__DemoProductBundleEntityProductBrand.php

Created on 21 Sep 2017  Â·  16Comments  Â·  Source: doctrine/orm

when i query entity with doctrine, i got this error message.
the query code:

$category = $this->getDoctrine()->getRepository('DemoProductBundle:Category')->find($nameId); $i = 0; $products = $this->getDoctrine()->getRepository('DemoProductBundle:Product')->findBy(array('porductCategory' => $category)); foreach ($products as $product) { dump($i); $i++; }

or
$category = $this->getDoctrine()->getRepository('DemoProductBundle:Category')->find($nameId); $i = 0; foreach ($category->getProducts() as $product) { dump($i); $i++; }

Error Message:

Warning: rename(...\var\cachedev/doctrine/orm/Proxies__CG__DemoProductBundleEntityBrand.php.59c31ec6f141e0.14539484,...\var\cachedev/doctrine/orm/Proxies\ __CG__DemoProductBundleEntityBrand.php): ܾ ʡ (code: 5)

when i used mysql_query replace doctrine, it worked.

$host = $this->getParameter('database_host'); $user= $this->getParameter('database_user'); $password = $this->getParameter('database_password'); $database = $this->getParameter('database_name'); $con = mysql_connect($host, $user, $password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); $sql = "SELECT * FROM demo_product WHERE category_id = $nameId"; // dump($sql); // exit(); $result = mysql_query($sql); $brandselect = "<option value='0'>please select...</option>"; while($row = mysql_fetch_object($result)) { $brandselect .= "<option value={$row->id}>{$row->title}</option>"; } mysql_close($con);

There are my yml files:

product.yml

`Demo\Bundle\ProductBundle\Entity\Product:
type: entity
table: demo_product
id:
id:
type: integer
nullable: false
options:
unsigned: true
id: true
generator:
strategy: IDENTITY
fields:
title:
type: string
nullable: true
length: 45
options:
fixed: false
sn:
type: string
nullable: true
length: 45
options:
fixed: false
excerpt:
type: string
nullable: true
length: 45
options:
fixed: false
description:
type: blob
nullable: true
length: 65535
options:
fixed: false
thumbnail:
type: string
nullable: true
length: 100
options:
fixed: false
pdf:
type: string
nullable: true
length: 100
options:
fixed: false
stock:
type: integer
nullable: true
options:
unsigned: false
price:
type: string
nullable: true
length: 45
options:
fixed: false
status:
type: string
nullable: true
length: 45
options:
fixed: false
created:
type: datetime
nullable: true
modified:
type: datetime
nullable: true

manyToOne:
    porductCategory:
        targetEntity: Category
        inversedBy: products
        joinColumns:
            category_id:
                referencedColumnName: id

    brand:
        targetEntity: Brand
        cascade: {  }
        fetch: LAZY
        mappedBy: null
        inversedBy: null
        joinColumns:
            brand_id:
                referencedColumnName: id
lifecycleCallbacks: {  }

`

productBrand.yml

Demo\Bundle\ProductBundle\Entity\Brand: type: entity table: demo_product_brand id: id: type: integer nullable: false options: unsigned: true id: true generator: strategy: IDENTITY fields: name: type: string nullable: true length: 45 options: fixed: false #简称 Abbreviation: type: string nullable: true length: 45 options: fixed: false sn: type: string nullable: true length: 45 options: fixed: false description: type: string nullable: true length: 45 options: fixed: false thumbnail: type: string nullable: true length: 45 options: fixed: false created: type: datetime nullable: true modified: type: datetime nullable: true lifecycleCallbacks: { }

productCategory.yml

`Demo\Bundle\ProductBundle\Entity\ProductCategory:
type: entity
table: demo_product_category

id:
    id:
        type: integer
        nullable: false
        options:
            unsigned: true
        id: true
        generator:
            strategy: IDENTITY
fields:
    categoryName:
        type: string
        nullable: true
        length: 45
        options:
            fixed: false
    categoryId:
        type: integer
        nullable: false
        length: 5
        options:
            fixed: false
    abbreviation:
        type: string
        nullable: false
        length: 20
        options:
            fixed: false
oneToMany:
    products:
        targetEntity: Product
        mappedBy: porductCategory
lifecycleCallbacks: {  }

`

what's wrong with my code? thanks.

Bug Can't Fix Incomplete

Most helpful comment

Same problem into vendordoctrine\common\lib\Doctrine\Common\Proxy\ProxyGenerator.php:293. To test:

  • Install Symfony in a Docker PHP7.2-fpm or PHP7.3-fpm.
  • Install doctrine/orm v2.6.4
  • Call Doctrine\ORM\EntityRepository->find($id)

All 16 comments

The issue is not with your code but with your dev environment. The error message points you toward the cache, which probably has the wrong permissions. You have to check your cache folder and fix the file permissions, but that may depend on what dev environment you have.

@Jean85 i tried to set cache permission. after clear cache, this error message is disappeared. but it will be displayed again in few times. the development environment is windows. i got this error when use ajax to load some data from database. if i pause 1-2 seconds for ajax loading, this error will not be displayed again.

I faced the same problem. It isn't because of permissions, it's because doctrine tries to regenerate proxies on each of ajax requests (in dev) and tries to write the file at the same time (multiple requests). Therefore some of requests are denied file access by OS.

However I haven't this happen in quite a while now... Try updating both doctrine and symfony, maybe it was fixed at some point

This issue as well as fix was documented here: https://github.com/doctrine/mongodb-odm/pull/1495
And here: https://github.com/doctrine/mongodb-odm/pull/1495
The HydratorFactory kept exploding on my local Docker about 50% of the time until I patched it locally by replacing single rename() operation with with copy() followed by unlink().

The authors of the library know about this issue and proposed fix but chose not to implement it.

We need a reproducible test case to fix this.

On 1 Oct 2017 15:03, "Eugene Luzgin" notifications@github.com wrote:

This issue as well as fix was documented here: doctrine/mongodb-odm#1495
https://github.com/doctrine/mongodb-odm/pull/1495
And here: doctrine/mongodb-odm#1495
https://github.com/doctrine/mongodb-odm/pull/1495
The HydratorFactory kept exploding on my local Docker about 50% of the
time until I patched it locally by replacing single rename() operation with
with copy() followed by unlink().

The authors of the library know about this issue and proposed fix but
chose not to implement it.

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
https://github.com/doctrine/doctrine2/issues/6713#issuecomment-333375278,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AAJakPknoRwILITfBTnnyc1OPOIbHrhGks5sn42-gaJpZM4PeuP6
.

Unfortunately I can not share my docker image since project source code is not mine.
Here is the screenshot of error however:

image

Details:

  • in /var/www/dir/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php line 415

  • at ErrorHandler->handle('2', 'rename(/var/www/dir/app/cache/dev/doctrine/odm/mongodb/Hydrators/MainBundleDocumentOmnitureAccountHydrator.php.59d0eb54bd23c1.56493991,/var/www/dir/app/cache/dev/doctrine/odm/mongodb/Hydrators/MainBundleDocumentOmnitureAccountHydrator.php): Operation not permitted', '/var/www/dir/vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php', '415', array('class' => object(ClassMetadata), 'hydratorClassName' => 'MainBundleDocumentOmnitureAccountHydrator', 'fileName' => '/var/www/dir/app/cache/dev/doctrine/odm/mongodb/Hydrators/MainBundleDocumentOmnitureAccountHydrator.php', 'code' => '<?php

  • Well aware of the error, just need a way to prevent regressions (test
    automation)

    On 1 Oct 2017 15:23, "Eugene Luzgin" notifications@github.com wrote:

    Unfortunately I can not share my docker image since project source code is
    not mine.
    Here is the screenshot of error however:

    [image: image]
    https://user-images.githubusercontent.com/561618/31054884-46d6c8ac-a679-11e7-8f84-f77a4f24132a.png

    Details:

    • in /var/www/trackingfirst/vendor/doctrine/mongodb-odm/lib/
      Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php line 415
    • at ErrorHandler->handle('2', 'rename(/var/www/
      trackingfirst/app/cache/dev/doctrine/odm/mongodb/Hydrators/
      TrackingFirstMainBundleDocumentOmnitureAccountHydrator.php.
      59d0eb54bd23c1.56493991,/var/www/trackingfirst/app/cache/
      dev/doctrine/odm/mongodb/Hydrators/TrackingFirstMainBundleDocumentOmnitureAccountHydrator.php):
      Operation not permitted', '/var/www/trackingfirst/
      vendor/doctrine/mongodb-odm/lib/Doctrine/ODM/MongoDB/Hydrator/HydratorFactory.php',
      '415', array('class' => object(ClassMetadata), 'hydratorClassName' =>
      'TrackingFirstMainBundleDocumentOmnitureAccountHydrator', 'fileName' =>
      '/var/www/trackingfirst/app/cache/dev/doctrine/odm/mongodb/Hydrators/
      TrackingFirstMainBundleDocumentOmnitureAccountHydrator.php', 'code' =>
      '

    —
    You are receiving this because you commented.
    Reply to this email directly, view it on GitHub
    https://github.com/doctrine/doctrine2/issues/6713#issuecomment-333376400,
    or mute the thread
    https://github.com/notifications/unsubscribe-auth/AAJakGTIqax_UipxAL_S0w1M9FEQT_Soks5sn5JMgaJpZM4PeuP6
    .

    The authors of the library know about this issue and proposed fix but chose not to implement it.

    Since you linked a pull request that suggested a change, allow me to also link the reason why I chose to not implement it: https://github.com/doctrine/mongodb-odm/pull/1495#issuecomment-251870697.
    Money quote:

    rename() is atomic while copy() isn't and can cause problems on slow file systems or with large files.

    One option would be to add a file_exists check for sanity before calling rename, but if you can't manage your operating system to make a simple rename('/foo/bar/a', '/foo/bar/b') work, this isn't something we're going to work around, at least not in ODM. Just saying.

    What's the best solution now? (while the ORM isn't updated yet)

    What's the best solution now? (while the ORM isn't updated yet)

    The solution that we used for our project was to apply this change locally - it worked for us: https://github.com/doctrine/mongodb-odm/pull/1495/files

    You mileage may vary.

    Well aware of the error, just need a way to prevent regressions (test automation)

    This has already been repeated twice in this thread.

    The authors don't want to integrate it for philosophical and performance reasons.

    Yes, because an issue that stems from people misconfiguring their virtualised environments should be fixed with an untested patch that can have severe performance implications for everyone else. It can also cause fatal errors due to incomplete cache files being read while the copy operation is in progress.

    Let me also ask you to tone down your language a bit: we’ve repeatedly explained why the solution proposed for ODM doesn’t work in most instances and that the issue is not with our code but the configuration of the system. This is the second time you’re insinuating that we’re not fixing that out of malice, and I won’t have it. Bring a fix with reproducible test cases that show you’re not introducing regressions for users that aren’t affected by this issue in the first place, or fix it for yourself without potentially introducing issues for millions of other users. Thank you for understanding.

    The authors don't want to integrate it for philosophical and performance reasons.

    Yes, because an issue that stems from people misconfiguring their virtualised environments should be fixed with an untested patch that can have severe performance implications for everyone else. It can also cause fatal errors due to incomplete cache files being read while the copy operation is in progress.

    Let me also ask you to tone down your language a bit: we’ve repeatedly explained why the solution proposed for ODM doesn’t work in most instances and that the issue is not with our code but the configuration of the system. This is the second time you’re insinuating that we’re not fixing that out of malice, and I won’t have it. Bring a fix with reproducible test cases that show you’re not introducing regressions for users that aren’t affected by this issue in the first place, or fix it for yourself without potentially introducing issues for millions of other users. Thank you for understanding.

    I apologize if I have insinuated anyones feelings. May comment was made with just a bit of sarcasm but no insinuating intentions. Regardless, this is an old problem.
    I am no longer involved in the project when we experienced this problem.
    I shared the approach we took to resolve the issue.
    I do not believe this was due to any misconfiguration of our Docker environment.

    If I was developer on this project I would code defensively and at least try to capture the error with rename (which happens on rare occasions) and try alternatives.

    Just my 2c.

    A solution provided in https://stackoverflow.com/questions/12894822/access-denied-error-on-rename-call-when-uploading-files-in-symfony was appropriate for me:

    private function renameWindowsCompatible($oldfile,$newfile) {
        try {
            rename($oldfile,$newfile);
        } catch(\Exception $e) {
            if (copy($oldfile,$newfile)) {
                unlink($oldfile);
                return TRUE;
            }
            return FALSE;
        }
        return TRUE;
    }
    

    Check https://github.com/webimpress/safe-writer/pull/1 and help with improving that - this is a common problem of atomic file writes done via rename, and needs extensive testing, but "hacking our own" in here ain't happening unless very carefully tested.

    Closing as "incomplete" here - please open a pull request if/when tests are part of a proposal.

    Same problem into vendordoctrine\common\lib\Doctrine\Common\Proxy\ProxyGenerator.php:293. To test:

    • Install Symfony in a Docker PHP7.2-fpm or PHP7.3-fpm.
    • Install doctrine/orm v2.6.4
    • Call Doctrine\ORM\EntityRepository->find($id)
    Was this page helpful?
    0 / 5 - 0 ratings