-
Notifications
You must be signed in to change notification settings - Fork 369
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
Don't assume connection is available in ORM::save #137
Conversation
If `ORM::save` is called before any other querying method and logging is enabled, logging will fail.
Do you have a regression test for this? |
I'm using idiorm and paris with SlimFramework. By default, SlimFramework turns notice-level errors into Exceptions, My code looks something like this: $factory = Model::factory('MyClass'); If this code is executed without any preceding query execution and with Undefined index: 'default' thrown by this line in ORM::_log_query: $parameters = array_map(array(self::$_db[$connection_name], 'quote'), Because, at least in my case, self::$_db['default'] doesn't exist yet. I dug into the code and what I found was that generally ORM::_setup_db is Having now explained this, I see that the same thing is probably possible ORM::delete If you agree to this fix, I'd be happy to amend my pull request to Cheers! Aaron Collegeman On Tue, Jul 16, 2013 at 7:46 AM, Simon Holywell [email protected]:
|
Have you definitely got the latest master versions of both Paris and Idiorm? I would have thought that this was unnecessary as there is a call to |
Yes, I have the latest. Just confirmed. Only difference between my idiorm Aaron Collegeman On Tue, Jul 16, 2013 at 12:03 PM, Simon Holywell
|
I have attempted to replicate this issue and I cannot. Here is my code: ini_set('error_reporting', E_ALL);
ini_set('show_errors', true);
require_once '../idiorm/idiorm.php';
require_once 'paris.php';
class CustomClass extends Model {
}
ORM::configure('logging', true);
ORM::configure('sqlite::memory:');
$factory = Model::factory('CustomClass');
$instance = $factory->create();
$instance->property = 'value';
$instance->save(); I am not seeing any errors or notices from this. I am removing it from the 1.4.0 milestone for now. Do you have any further detail? |
I am looking to release 1.4.0 in the coming week. If this is still causing an issue please update the ticket with more information. Thanks. |
Thanks Simon! I don't have any further detail. The projects I was using Aaron Collegeman On Tue, Sep 3, 2013 at 7:56 AM, Simon Holywell [email protected]:
|
Any chance you were using cached items? I've got into this problem while caching my objects (resources variables cannot be stored in the cache). Taking the other places you mentioned, I have a little different version on a fork here: https://github.com/falmp/idiorm/tree/lazy-connection How do I run the tests? I'm afraid I'm doing something wrong because I tried running phpunit against master before doing my changes but I got this error:
|
@falmp We have recently had a similar issue with the Paris tests: j4mie/paris#75 (comment) It all works fine on Travis and locally for me however. Is there anything special about your configuration? |
Nope, except maybe it's the latest PHP version?
|
I have not tried to run Idiorm or Paris on PHP 5.5 so I don't know if that is the cause. Have you stepped through to find the source of the error? |
Well, yes, the error is:
Which is this piece of code: protected static function _detect_identifier_quote_character($connection_name) {
switch(self::$_db[$connection_name]->getAttribute(PDO::ATTR_DRIVER_NAME)) {
case 'pgsql':
case 'sqlsrv':
case 'dblib':
case 'mssql':
case 'sybase':
case 'firebird':
return '"';
case 'mysql':
case 'sqlite':
case 'sqlite2':
default:
return '`';
}
} I added a
I don't fully understand the Idiorm internals, not sure where it was supposed to initialize the |
Looks like the connection has either not been setup yet or it has been disconnected earlier than anticipated. I imagine that when you're running the tests that the order of |
I tried another approach with the lazy initialization which fixes my last problem with cached entities and also the test run, so I was able to run the tests under PHP 5.5.4:
I proceeded with a pull request under #159 and I'd really appreciate it if you could pull this in. |
I am going to go with @falmp pull request. @collegeman please could you test that his pull request (#159) also resolves your issue. I am pretty sure it will. |
If
ORM::save
is called before any other querying method and logging is enabled, logging will fail.