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

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

Closed
xiranst opened this issue Sep 21, 2017 · 16 comments

Comments

@xiranst
Copy link

xiranst commented Sep 21, 2017

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\cache\dev/doctrine/orm/Proxies__CG__DemoProductBundleEntityBrand.php.59c31ec6f141e0.14539484,...\var\cache\dev/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.

@Jean85
Copy link
Contributor

Jean85 commented Sep 22, 2017

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.

@xiranst
Copy link
Author

xiranst commented Sep 22, 2017

@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.

@Xymanek
Copy link

Xymanek commented Sep 30, 2017

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

@eluzgin
Copy link

eluzgin commented Oct 1, 2017

This issue as well as fix was documented here: doctrine/mongodb-odm#1495
And here: doctrine/mongodb-odm#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.

@Ocramius
Copy link
Member

Ocramius commented Oct 1, 2017 via email

@eluzgin
Copy link

eluzgin commented Oct 1, 2017

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
  • @Ocramius
    Copy link
    Member

    Ocramius commented Oct 1, 2017 via email

    @alcaeus
    Copy link
    Member

    alcaeus commented Oct 1, 2017

    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: doctrine/mongodb-odm#1495 (comment).
    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.

    klammbueddel pushed a commit to klammbueddel/common that referenced this issue Jul 1, 2019
    ...to move a file without side effects.
    
    This gist reproduces the problem:
    https://gist.github.com/alcaeus/a367e895e6c55f7fb93870dcba46efa9
    
    Same issue is fixed in a similary way in symfony core:
    symfony/symfony#12533
    
    resolves doctrine/orm#6713
    @glennthehuman
    Copy link

    glennthehuman commented Aug 6, 2019

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

    @eluzgin
    Copy link

    eluzgin commented Aug 6, 2019

    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.

    @Ocramius
    Copy link
    Member

    Ocramius commented Aug 6, 2019

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

    This has already been repeated twice in this thread.

    @alcaeus
    Copy link
    Member

    alcaeus commented Aug 6, 2019

    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.

    @eluzgin
    Copy link

    eluzgin commented Aug 6, 2019

    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.

    @ElMatella
    Copy link

    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;
    }

    @Ocramius
    Copy link
    Member

    Check webimpress/safe-writer#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.

    @JackPotte
    Copy link

    Same problem into vendor\doctrine\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)

    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Projects
    None yet
    Development

    No branches or pull requests

    9 participants