-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
[BUG]: Phalcon v5.0.2 + PHP 8.1 - Model caching error #16131
Comments
@Alistar84 could you please post a sample model and code with some potential data? I want to create a test to diagnose this. Thanks |
After some investigation, I realized that the problem occurs only if in the column list there are values like CONCAT, DISTINCT, GROUP_CONCAT, COUNT, ... This is the code: BaseModel class BaseModel extends \Phalcon\Mvc\Model {
[...]
public static function find($parameters = null): ResultsetInterface {
$parameters = self::excludeSoftDelete($parameters);
return parent::find($parameters);
}
public static function findFirst($parameters = null): ?ModelInterface {
$parameters = self::excludeSoftDelete($parameters);
return parent::findFirst($parameters);
}
protected static function forceCache(string $key, $parameters = null): array{
if($parameters !== null){
if(is_array($parameters) !== true) $parameters = [$parameters];
if(isset($parameters['cache']) !== true) $parameters['cache'] = ['key' => $key, 'lifetime' => 86400];
}else{
$parameters = ['cache' => ['key' => $key, 'lifetime' => 86400]];
}
return $parameters;
}
} Robots model class Robots extends BaseModel
{
/**
*
* @var integer
* @Primary
* @Identity
* @Column(column="id", type="integer", length=2, nullable=false)
*/
public $id;
/**
*
* @var integer
* @Column(column="id_status", type="integer", length=1, nullable=false)
*/
public $id_status;
/**
* Initialize method for model.
*/
public function initialize()
{
parent::initialize();
$this->setSource("robots");
}
public static function find($parameters = null): \Phalcon\Mvc\Model\ResultsetInterface
{
$key = 'Robots_find_'.md5(json_encode($parameters));
$parameters = parent::forceCache($key, $parameters);
return parent::find($parameters);
}
public static function findFirst($parameters = null): ?\Phalcon\Mvc\ModelInterface
{
$key = 'Robots_findFirst_'.md5(json_encode($parameters));
$parameters = parent::forceCache($key, $parameters);
return parent::findFirst($parameters);
}
} Controller $data = Robots::find(['columns' => ['COUNT(id)'], 'conditions' => 'id_status = 2']); Phalcon version: 5.0.2 |
I have same issue in 5.0.3. There is a quick code to check (in some controller, and you can change with your infrastructure models): $builder = $this->modelsManager->createBuilder();
$builder->columns('v.*, p.*');
$builder->addFrom('Models\ProductVariants', 'v');
$builder->join('Models\Products', 'p.id=v.product_id', 'p');
$builder->getQuery()->cache(['key' => 'product-test-relation', 'lifetime' => 1])->execute(); So... If you change |
I will check this out this week |
@niden thanks a lot! |
Fixed in #16036 |
@borisdelev please confirm if it fixed in |
@Jeckerson yes, it work. Just update the hosting with 5.0.4 :) Thanks for everything :) |
Discussed in #16130
Originally posted by Alistar84 September 29, 2022
Hello everybody,
I have a problem with model caching.
In v4 all my models extend a class that implements a force cache system similar to this one https://docs.phalcon.io/5.0/en/db-models-cache#forcing-cache
Now, in v5, if I run a find or findFirst that is already cached, I've got this error:
Fatal error: Uncaught TypeError: unserialize(): Argument #1 ($data) must be of type string, array given.
How can I solve?
The text was updated successfully, but these errors were encountered: