nextras / orm

Orm with clean object design, smart relationship loading and powerful collections.
https://nextras.org/orm
MIT License
309 stars 59 forks source link

Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in [no active file] #389

Closed camohub closed 4 years ago

camohub commented 4 years ago

Hi, I have a simple sign in form which throws me a weird error after success which seems to be related to Nextras/Orm. System configuration looks like: php: 7.2.25 "nextras/orm": "^3.1", "nette/application": "^3.0", "nette/bootstrap": "^3.0", "nette/caching": "^3.0", "nette/database": "^3.0", "nette/di": "^3.0", "nette/finder": "^2.5", "nette/forms": "^3.0", "nette/http": "^3.0", "nette/mail": "^3.0", "nette/robot-loader": "^3.0", "nette/security": "^3.0", "nette/utils": "^3.0", "latte/latte": "^2.5", "tracy/tracy": "^2.6", "kdyby/translation": "^3.0",

Its a new aplication so the packages should be the latest...

The one weird thing is Tracy does not catch the error it is like a PHP text. Here is an error message:


Fatal error: Uncaught Exception: Serialization of 'Closure' is not allowed in [no active file] on line 0 
Nextras\Dbal\QueryException: You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 
'SET time_zone = 'Europe/Prague'' at line 1 in C:\wamp64-3-2-0\www\tatrydevelopment\vendor\nextras\dbal\src\Drivers\Mysqli\MysqliDriver.php on line 385 
Call Stack: 0.2427 2823608 
1. Tracy\Debugger::shutdownHandler() C:\wamp64-3-2-0
\www\tatrydevelopment\vendor\tracy\tracy\src\Tracy\Debugger\Debugger.php:0 0.2427 2320656 
2. Tracy\Bar->render() C:\wamp64-3-2-0\www\tatrydevelopment\vendor\tracy\tracy\src\Tracy\Debugger\Debugger.php:276 0.2428 2320784 
3. Tracy\Bar->renderHtml() C:\wamp64-3-2-0\www\tatrydevelopment\vendor\tracy\tracy\src\Tracy\Bar\Bar.php:97 0.2428 2320784 
4. Tracy\Bar->renderPanels() C:\wamp64-3-2-0\www\tatrydevelopment\vendor\tracy\tracy\src\Tracy\Bar\Bar.php:121 0.3194 3647048 
5. Nextras\Dbal\Bridges\NetteTracy\ConnectionPanel->getPanel() C:\wamp64-3-2-0\www\tatrydevelopment\vendor\tracy\tracy\src\Tracy\Bar\Bar.php:149 0.3194 3647368 
6. array_map() C:\wamp64-3-2-0\www\tatrydevelopment\vendor\nextras\dbal\src\Bridges\NetteTracy\ConnectionPanel.php:100 0.3202 3730096 
7. Nextras\Dbal\Bridges\NetteTracy\ConnectionPanel->Nextras\Dbal\Bridges\NetteTracy\{closure:C:\wamp64-3-2-0\www\tatrydevelopment\vendor\nextras\dbal\src\Bridges\NetteTracy\ConnectionPanel.php:87-100}() C:\wamp64-3-2-0\www\tatrydevelopment\vendor\nextras\dbal\src\Bridges\NetteTracy\ConnectionPanel.php:100 0.3202 3730536 
8. Nextras\Dbal\Drivers\Mysqli\MysqliDriver->query() C:\wamp64-3-2-0\www\tatrydevelopment\vendor\nextras\dbal\src\Bridges\NetteTracy\ConnectionPanel.php:91```
camohub commented 4 years ago

I found out it is related to Nette Authenticator where identity cant contain relations. In my implentation is this piece code, where the user->roles M:M relation hrows this error:

$rolesArr = [];
foreach ( $user->roles as $role ) {
    $rolesArr[] = $role->name;
}
$userArr = $user->toArray();

// unset($userArr['roles']);  // This M:M relation is the problem if it is stored as a thidr param of next Identity constructor. I am not sure if it is bug or how to solve it.

return new Nette\Security\Identity( $userArr['id'], $rolesArr, $userArr );
camohub commented 4 years ago

Ok I have it. $userArr = $user->toArray(ToArrayConverter::RELATIONSHIP_AS_ARRAY);

hrach commented 4 years ago

Generally, we encourage users NOT to store entity (neither their all data) in session (Indentity), but rather store the primary key and fetch the entity again during each request.