Description
Description
I'm in the middle of upgrading a project from Craft 4 to Craft 5.
While testing, I'm getting the following serialization Exception. At the bottom of the screenshot you'll see the SendEmail job being added.
Turns out it was caused by a custom behavior I had that was using PHP 8.1 first class callable syntax in some events & validations.
public function events(): array
{
return [
Order::EVENT_AFTER_SAVE => $this->_afterSave(...), // Serialization does not like
];
}
That was easy enough to fix... but made me think that serializing the entire Order Element might be unintended behavior.
There seems to be logic that expects only the Order ID to be stored in the queue table and then lazily loaded when needed.
The cause of the private $_order property getting populated seems to come from defaultDescription()
Happy to submit a PR if this is unintended behavior.
Steps to reproduce
Simply completing checkout will cause an Order to be serialized alongside the SendEmail queue job.
If you wish to reproduce the serlization error, attach a behavior to the Order element that includes a closure.
<?php
namespace my\custom\namespace
use craft\commerce\elements\Order;
use yii\base\Behavior;
class MyOrderBehavior extends Behavior
{
/** @var Order */
public $owner;
public function events(): array
{
return [
Order::EVENT_AFTER_SAVE => '_afterSave',
];
}
public function _afterSave(): void
{
// Does stuff
}
}
Craft CMS version
5.7.4
Craft Commerce version
5.3.10
PHP version
8.3
Operating system and version
DDEV
Database type and version
MySQL 8.0.36
Image driver and version
No response