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

2.9.2: Statamic\Data\Users\Eloquent\User recursion when getting attribute #1966

Closed
Keoghan opened this Issue May 24, 2018 · 0 comments

Comments

Projects
None yet
4 participants
@Keoghan

Keoghan commented May 24, 2018

Retrieving a value from a model causes an infinite recursion in using this model - for example when used for user authentication.

To Reproduce
Steps to reproduce the behavior:

  1. Upgrade a Statamic site using Eloquent users for authentication
  2. Attempt to access the site or run php please.

Expected behavior
The site to load up or console to finish.

Screenshots
Not needed, recursion occurs in output trace.

Environment details (please complete the following information):

  • Statamic Version 2.9.2
  • Upgrade
  • OS: MacOS High Sierra
  • Browser: All
  • Web Server: Valet
  • PHP Version: 7.1.6

Additional context
The error appears to be in the Statamic\Data\Users\Eloquent\User model.

It is currently doing this:

...
public function model(UserModel $model = null)
    {
        if (is_null($model)) {
            if (! $this->model) {
                $this->model = new UserModel;
            }

           // Since this runs even when the model is available, every request to fieldset() ends up recursing
            $this->model->mergeCastsFromFieldset($this->fieldset());

            return $this->model;
        }

        $this->model = $model;
    }

I think the solution is this (certainly it allows the app to continue):

public function model(UserModel $model = null)
    {
        if (is_null($model)) {
            if (! $this->model) {
                $this->model = new UserModel;
                $this->model->mergeCastsFromFieldset($this->fieldset());
            }

            return $this->model;
        }

        $this->model = $model;
       // this might also be needed
       $this->model->mergeCastsFromFieldset($this->fieldset());
    }

Thanks for an excellent product.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment