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] Updating a model fails after fetching its related records #13964

Closed
zsilbi opened this issue Apr 9, 2019 · 4 comments
Closed

[BUG] Updating a model fails after fetching its related records #13964

zsilbi opened this issue Apr 9, 2019 · 4 comments
Labels
bug A bug report status: low Low

Comments

@zsilbi
Copy link
Member

zsilbi commented Apr 9, 2019

When fetching a record (Robots) and getting it's related models (RobotParts) a RuntimeException is being thrown when trying to save/update afterwards.

My observations:

  • It only happens when after accessing hasMany or hasManyToMany type of relations.
  • I have tried a lot of different models (names, aliases) and relations
  • When creating a new model the error not occurs
  • It doesn't matter if there are any related records in RobotParts table
  • It only occurs when accessing the related records as property (saving after $robot->getRobotParts() works fine)

Output error when using hasMany

RuntimeException
Call to undefined method \x01::writeattribute() 

Output error when using hasManyToMany

RuntimeException
Call to undefined method \x01::save() 

Script to reproduce the issue (only the relevant parts)

class Robots extends \Phalcon\Mvc\Model {
    public function initialize() {
        $this->hasMany('id', 'RobotParts', 'robotId', [
            'alias' => 'robotParts'
        ]);
    }
}

public function main() {
    $robot = Robots::findFirst();
    $robot->robotParts;
    $robot->save(); // or $robot->update();
}

Current workaround:

public function main() {
    $robot = Robots::findFirst();
    $robot->getRobotParts();
    $robot->save();
}

It's a widely used feature and it's very easy to reproduce so I think - and hope - that it must be some kind of incompability, otherwise it would have been discovered previously.

Details

  • Phalcon version: 4.0.0-alpha.3
  • PHP Version: 7.2.16-1
  • Operating System: Ubuntu 16.04
  • Installation type: Compiling from source
  • Zephir version (if any): Version 0.11.11-b661a58
  • Server: nginx
  • Other related info (Database, table schema): MariaDB 10.1.37
@zsilbi
Copy link
Member Author

zsilbi commented Apr 12, 2019

I wrote tests to confirm the issue and it failed in CI with a rather strange error message.

[PHPUnit\Framework\Exception] Invalid callback , no array or string given

@zsilbi zsilbi changed the title Updating a model fails after fetching its related records [BUG] Updating a model fails after fetching its related records Apr 15, 2019
zsilbi pushed a commit to zsilbi/cphalcon that referenced this issue Apr 15, 2019
@niden niden added this to To do in 4.0.0 Release via automation Apr 16, 2019
zsilbi pushed a commit to zsilbi/cphalcon that referenced this issue Apr 16, 2019
niden pushed a commit that referenced this issue Apr 16, 2019
* Disabled saving related the records to _related when access via __get()
Added specific tests for issue #13964.

* Code style fix.

* Disabled saving related the records to _related when access via __get()
Added specific tests for issue #13964.

* Code style fix.

* Added changelog for #13985
@niden
Copy link
Sponsor Member

niden commented Apr 16, 2019

Resolved

@niden niden closed this as completed Apr 16, 2019
4.0.0 Release automation moved this from To do to Done Apr 16, 2019
@niden niden reopened this Apr 16, 2019
4.0.0 Release automation moved this from Done to In progress Apr 16, 2019
@niden
Copy link
Sponsor Member

niden commented Apr 16, 2019

Actually my bad, this was not resolved 100%. We need to do a lot more regression testing with the proposed fix from the PR attached to this issue.

zsilbi pushed a commit to zsilbi/cphalcon that referenced this issue Apr 26, 2019
Added tests to confirm relation storage cache
Added tests for issue phalcon#13964
zsilbi pushed a commit to zsilbi/cphalcon that referenced this issue May 2, 2019
Added tests to confirm relation storage cache
Added tests for issue phalcon#13964
zsilbi pushed a commit to zsilbi/cphalcon that referenced this issue May 2, 2019
Added tests to confirm relation storage cache
Added tests for issue phalcon#13964
@niden
Copy link
Sponsor Member

niden commented May 11, 2019

Resolved in #14035

@niden niden closed this as completed May 11, 2019
4.0.0 Release automation moved this from In progress to Done May 11, 2019
@niden niden added the 4.0 label Jun 21, 2019
@niden niden added bug A bug report status: low Low and removed Bug - Low labels Dec 23, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug A bug report status: low Low
Projects
No open projects
4.0.0 Release
  
Done
Development

No branches or pull requests

2 participants