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

[2.x] Proxy that's passed in an array duplicates object on save #712

Closed
KDederichs opened this issue Oct 28, 2024 · 2 comments
Closed

[2.x] Proxy that's passed in an array duplicates object on save #712

KDederichs opened this issue Oct 28, 2024 · 2 comments

Comments

@KDederichs
Copy link
Contributor

KDederichs commented Oct 28, 2024

When you create and return a proxy object in an array and then try to call _save() on that it'll try to re-insert the object causing duplicate key exceptions.

class BaseFoo {
    public function makeFixture(): array
    {
        $bar = BarRepository::createOne();
	
        return ['barFixture' => $bar];
	}
}

class FooTest extends BaseFoo
{
    public function testFoo()
    {
        $fixtures = $this->makeFixture();
        $fixtures['barFixture']->setBaz('a');
        $fixtures['barFixture']->_save(); //Causing exception here
    }
}

Again calling _real() before setting the values fixes this which makes me suspect that it's related to #710 but I'll report it as separate for now in case it's not.

@nikophil
Copy link
Member

nikophil commented Oct 29, 2024

Please, could you share the factories + the error (with stack trace of possible)?

I can't see why returning and acting on an array does create a problem.
Does the following works?

$bar = BarRepository::createOne();
$bar->setBaz('a');	
$bar->_save();

the best for both of those problems would be to create a reproducer app, if possible 🙏

thanks

@KDederichs
Copy link
Contributor Author

Hmm yeah can't seem to reproduce that one, strange I'll give you one for the other issue though

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

No branches or pull requests

2 participants