Skip to content
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]: find and findFirst fails with exception from Phalcon\Mvc\Model->toArray if there is APCU model cache enabled #15711

Open
elcreator opened this issue Oct 6, 2021 · 1 comment
Assignees
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium

Comments

@elcreator
Copy link
Sponsor

elcreator commented Oct 6, 2021

Describe the bug
find and findFirst fails with exception from Phalcon\Mvc\Model->toArray if there is APCU model cache enabled.

To Reproduce
[06-Oct-2021 23:20:27 Europe/Kiev] PHP Fatal error: Uncaught Error: Typed property Auth\Models\User::$email must not be accessed before initialization in /home/project/includes/BaseModel.php:33
Stack trace:
#0 /home/project/includes/BaseModel.php(33): Phalcon\Mvc\Model->toArray()
#1 [internal function]: BaseModel->toArray()
#2 [internal function]: Phalcon\Mvc\Model->serialize()
#3 [internal function]: serialize()
#4 [internal function]: Phalcon\Mvc\Model\Resultset\Simple->serialize()
#5 [internal function]: serialize()
#6 [internal function]: Phalcon\Storage\Serializer\Php->serialize()
#7 [internal function]: Phalcon\Storage\Adapter\AbstractAdapter->getSerializedData()
#8 [internal function]: Phalcon\Storage\Adapter\Apcu->set()
#9 [internal function]: Phalcon\Cache->set()
#10 [internal function]: Phalcon\Mvc\Model\Query->execute()
#11 /home/project/includes/BaseModel.php(112): Phalcon\Mvc\Model::findFirst()
#12 /home/project/modules/auth/controllers/LoginController.php(22): BaseModel::findFirst()
#13 [internal function]: Auth\Controllers\LoginController->login in /home/project/includes/BaseModel.php on line 33

Steps to reproduce the behavior:
https://github.com/elcreator/phalcon-demo/blob/main/includes/BaseModel.php#L117 - uncomment this to see the failure.
It works if these lines remain commented (i.e. when cache parameter is absent).
Refer to https://docs.phalcon.io/4.0/en/db-models-cache example as cache was taken from this doc

Expected behavior
Error should not be thrown

Details

  • Phalcon version: (php --ri phalcon) 5.0.0alpha6
  • PHP Version: (php -v) 7.4
  • Operating System: Ubuntu 20
  • Installation type: pear install
  • Zephir version (if any): 0.14.0-beta.3-0be9ad5
  • Server: Nginx
  • Other related info (Database, table schema): MySQL

Additional context
https://github.com/elcreator/phalcon-demo follow readme to get environment with DB to reproduce this issue when trying to login

Get familiar with https://github.com/elcreator/phalcon-demo/blob/main/modules/auth/controllers/LoginController.php
https://github.com/elcreator/phalcon-demo/blob/main/modules/auth/models/EmailUser.php
https://github.com/elcreator/phalcon-demo/blob/main/modules/auth/models/User.php

@elcreator elcreator added bug A bug report status: unverified Unverified labels Oct 6, 2021
@Jeckerson Jeckerson added the 5.0 The issues we want to solve in the 5.0 release label Nov 7, 2021
@BeMySlaveDarlin
Copy link
Contributor

BeMySlaveDarlin commented Nov 9, 2021

This is related to how typed properties works in php7.4+ and the way we initialize models.
For now, to fix this issue, we need to change the logic of models initializasion in Phalcon\Mvc\Model::unserialize().
Highly likely it will cause bbc.

@BeMySlaveDarlin BeMySlaveDarlin added status: medium Medium and removed status: unverified Unverified labels Nov 9, 2021
@Jeckerson Jeckerson assigned niden and unassigned BeMySlaveDarlin Nov 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
5.0 The issues we want to solve in the 5.0 release bug A bug report status: medium Medium
Projects
Status: Active Sprint
Development

No branches or pull requests

4 participants