Giter Site home page Giter Site logo

Comments (11)

pmjones avatar pmjones commented on August 23, 2024 1

@dijitaltrix I have merged the fix from @sunkan into the 2.x branch, with a refactoring of the logic therein. Try it out and let me know if it still works for you; if it does, I'll make a release.

Thanks, everyone, for your work here.

from atlas.orm.

pmjones avatar pmjones commented on August 23, 2024

Hi @dijitaltrix --

I am unable to reproduce the error you describe. I tried doing so in the issue-86 branch, via this commit: 0c7cd7e

Take a look at that test, and let me know how to make it match your case more closely.

from atlas.orm.

dijitaltrix avatar dijitaltrix commented on August 23, 2024

Hi @pmjones,

Thanks for taking a look, it may be the issue is with MariaDB or the PDO driver.

I've run the tests from Issue-86 and can confirm they test ok against an sqlite memory database, I've not modified the test you supplied as the issue only seems to occur using MySQL and though I modified the phpunit tests in orm/tests they threw a few errors due to backticks and I wasn't confident of the results.

I've created a repository here https://github.com/dijitaltrix/Issue-86 with the minimum code required to show the issue. It follows the examples in the docs and the code in Issue86 very closely.

You'll see two files mysql_create.php and sqlite_create.php they are identical apart from the new AtlasContainer() statement.

The Sqlite code runs as excepted, it creates the parent and relations as it should, and when an Exception is thrown no records are created.

With MySQL the same code gives this error:

The Transaction failed:
persist Test\Parent\ParentRecord via Test\Parent\ParentMapper threw exception Expected 1 row affected, actual 0.

from atlas.orm.

sunkan avatar sunkan commented on August 23, 2024

Hi @dijitaltrix

I looked at your tests and the error is because you are trying to use time() on an mysql date type.

And that don't work so I change to date('Y-m-d') in you test data after that I get the correct exception.

A better question might be why PDO don't report the error from mysql

from atlas.orm.

dijitaltrix avatar dijitaltrix commented on August 23, 2024

Hi @sunkan
Thanks for taking a look, I should have spotted that! As you say the example does run fine when given the correct data! I have updated the example as I'm still seeing the issue, please would you check again.

from atlas.orm.

dijitaltrix avatar dijitaltrix commented on August 23, 2024

Hi @pmjones
I've updated my example, now it's looping through a data array and creating records off that. The issue only occurs if a subsequent transaction fails.

There's four test files now.. I assumed the issue was only occurring in MySQL but it also occurs in Sqlite, they're almost identical as before so take your pick!

I think the issue may be to do with the response from an Aura SQL call $this->pdo->inTransaction() it seems to return 1 on the first transaction but not on subsequent transactions.

from atlas.orm.

sunkan avatar sunkan commented on August 23, 2024

The problem is in Atlas\Orm\Table\ConnectionManager::getConnection

It checks if the connection already exists and just returns it.

It should also check inTransaction is true like this

if (isset($this->conn[$type][$tableClass])) {
    if ($this->inTransaction() && ! $this->conn[$type][$tableClass]->inTransaction()) {
        $this->conn[$type][$tableClass]->beginTransaction();
    }
    return $this->conn[$type][$tableClass];
}

I will put together a pull request in a an hour need to do some actual work now :)

@pmjones

from atlas.orm.

pmjones avatar pmjones commented on August 23, 2024

@sunkan I look forward to it, and thanks!

from atlas.orm.

dijitaltrix avatar dijitaltrix commented on August 23, 2024

@sunkan commit #87 has fixed the issue for me, thank you!

from atlas.orm.

dijitaltrix avatar dijitaltrix commented on August 23, 2024

@pmjones, @sunkan Thanks, I've tested the fix with my example code and it's working as expected, I assumed it was an issue with MySQL hence I created the example and didn't modify your unit tests. I'll write a test and create a pull request.

from atlas.orm.

pmjones avatar pmjones commented on August 23, 2024

Closing this as "bug has been fixed" and will wait for separate PR from @dijitaltrix for a test. Thanks everyone!

from atlas.orm.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.