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] Update 5.0.15 to 5.0.16 (and after) - Impossible to save/create #4381

Closed
KevinCassier opened this issue May 17, 2022 · 22 comments · Fixed by #4459
Closed

[Bug] Update 5.0.15 to 5.0.16 (and after) - Impossible to save/create #4381

KevinCassier opened this issue May 17, 2022 · 22 comments · Fixed by #4459
Assignees
Labels
Possible Bug A bug that was reported but not confirmed yet. Priority: MUST URGENT

Comments

@KevinCassier
Copy link
Contributor

Bug report

What I did

I updated from 5.0.15 to 5.0.16, and just try to create / or update an entity.

What I expected to happen

My entity is saved.

What happened

It doesn't work and I have an error like

  • "Call to a member function only() on array" when I create
  • "Call to a member function get() on array" when I update

What I've already tried to fix it

Impossible to find why.
The only thing I noticed is that only on a model which extend the update/store method (with an traitStore/traitUpdate inside)
The error occur when $response = $this->traitStore() or $response = $this->traitUpdate() is call

Is it a bug in the latest version of Backpack?

Yes

Thanks for you help

@tabacitu tabacitu added the Possible Bug A bug that was reported but not confirmed yet. label May 17, 2022
@pxpm
Copy link
Contributor

pxpm commented May 17, 2022

Hello @KevinCassier

I will need some more information to work with here. In what file the error is triggered ? Can you post the full error stacktrace ?

Cheers

@pxpm pxpm removed the triage label May 17, 2022
@tabacitu
Copy link
Member

tabacitu commented May 18, 2022

Also, if it only happens when traitStore() and traitUpdate() are called, it could be useful to see the overriding methods too.

@madviking
Copy link

Here is a full stack trace. I was unable to replicate on my dev, but production version gives this error.

production.ERROR: Call to a member function get() on array {"userId":2,"exception":"[object] (Error(code: 0): Call to a member function get() on array at /var/www/vendors/vendors-portal/vendor/backpack/crud/src/app/Http/Controllers/Operations/UpdateOperation.php:98)
[stacktrace]
#0 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\Modules\CandidateController->update()
#1 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#2 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Route.php(262): Illuminate\Routing\ControllerDispatcher->dispatch()
#3 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#4 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\Routing\Route->run()
#5 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#6 /var/www/vendors/vendors-portal/vendor/backpack/crud/src/app/Http/Controllers/CrudController.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#7 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(149): Backpack\CRUD\app\Http\Controllers\CrudController->Backpack\CRUD\app\Http\Controllers\{closure}()
#8 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php(50): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#9 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\SubstituteBindings->handle()
#10 /var/www/vendors/vendors-portal/app/Http/Middleware/Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#11 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\Authenticate->handle()
#12 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php(78): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#13 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\VerifyCsrfToken->handle()
#14 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#15 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#16 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Session/Middleware/AuthenticateSession.php(58): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#17 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\AuthenticateSession->handle()
#18 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#19 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#20 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle()
#21 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php(37): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse->handle()
#23 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php(67): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#24 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Cookie\Middleware\EncryptCookies->handle()
#25 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#26 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(723): Illuminate\Pipeline\Pipeline->then()
#27 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(698): Illuminate\Routing\Router->runRouteWithinStack()
#28 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\Routing\Router->runRoute()
#29 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\Routing\Router->dispatchToRoute()
#30 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Routing\Router->dispatch()
#31 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#32 /var/www/vendors/vendors-portal/vendor/livewire/livewire/src/DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Livewire\DisableBrowserCache->handle()
#34 /var/www/vendors/vendors-portal/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(60): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#35 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#36 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#37 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#38 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#39 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#40 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php(40): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#41 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\TrimStrings->handle()
#42 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php(27): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#43 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ValidatePostSize->handle()
#44 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#45 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#46 /var/www/vendors/vendors-portal/vendor/fruitcake/laravel-cors/src/HandleCors.php(38): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#47 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle()
#48 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php(39): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#49 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Http\Middleware\TrustProxies->handle()
#50 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#51 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Pipeline\Pipeline->then()
#52 /var/www/vendors/vendors-portal/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#53 /var/www/vendors/vendors-portal/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#54 {main}
"}

@pxpm
Copy link
Contributor

pxpm commented May 18, 2022

Well, the only place where we use get() in that file is $request->get(), since you are overriding the store functions I guess you migth be manipulating the request and making it an array instead of a Request instance.

Could that be the problem ?

@madviking
Copy link

Well, the only place where we use get() in that file is $request->get(), since you are overriding the store functions I guess you migth be manipulating the request and making it an array instead of a Request instance.

Could that be the problem ?

This is possible yes. It is most probably related to modifying relations, maybe unsetting a relation could be the culprit. I will try to test and investigate more. But this has been working ok on 5.0.14 at least.

@KevinCassier
Copy link
Contributor Author

KevinCassier commented May 18, 2022

Hi @pxpm,

Here is the trace of the error

Error Call to a member function get() on array vendor/backpack/crud/src/app/Http/Controllers/Operations/UpdateOperation.php:98 App\Http\Controllers\Admin\FolderActionCrudController::traitUpdate app/Http/Controllers/Admin/FolderActionCrudController.php:211 App\Http\Controllers\Admin\FolderActionCrudController::update vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54 Illuminate\Routing\Controller::callAction vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:45 Illuminate\Routing\ControllerDispatcher::dispatch vendor/laravel/framework/src/Illuminate/Routing/Route.php:261 Illuminate\Routing\Route::runController vendor/laravel/framework/src/Illuminate/Routing/Route.php:204 Illuminate\Routing\Route::run vendor/laravel/framework/src/Illuminate/Routing/Router.php:725 Illuminate\Routing\Router::Illuminate\Routing\{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/backpack/crud/src/app/Http/Controllers/CrudController.php:44 Backpack\CRUD\app\Http\Controllers\CrudController::Backpack\CRUD\app\Http\Controllers\{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:162 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/backpack/crud/src/app/Http/Middleware/UseBackpackAuthGuardInsteadOfDefaultAuthGuard.php:21 Backpack\CRUD\app\Http\Middleware\UseBackpackAuthGuardInsteadOfDefaultAuthGuard::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 Illuminate\Foundation\Http\Middleware\TransformsRequest::handle vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php:31 Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} app/Http/Middleware/CheckIfAdmin.php:65 App\Http\Middleware\CheckIfAdmin::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:50 Illuminate\Routing\Middleware\SubstituteBindings::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:78 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49 Illuminate\View\Middleware\ShareErrorsFromSession::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:121 Illuminate\Session\Middleware\StartSession::handleStatefulRequest vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64 Illuminate\Session\Middleware\StartSession::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67 Illuminate\Cookie\Middleware\EncryptCookies::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116 Illuminate\Pipeline\Pipeline::then vendor/laravel/framework/src/Illuminate/Routing/Router.php:726 Illuminate\Routing\Router::runRouteWithinStack vendor/laravel/framework/src/Illuminate/Routing/Router.php:703 Illuminate\Routing\Router::runRoute vendor/laravel/framework/src/Illuminate/Routing/Router.php:667 Illuminate\Routing\Router::dispatchToRoute vendor/laravel/framework/src/Illuminate/Routing/Router.php:656 Illuminate\Routing\Router::dispatch vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:167 Illuminate\Foundation\Http\Kernel::Illuminate\Foundation\Http\{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/livewire/livewire/src/DisableBrowserCache.php:19 Livewire\DisableBrowserCache::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 Illuminate\Foundation\Http\Middleware\TransformsRequest::handle vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php:31 Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 Illuminate\Foundation\Http\Middleware\TransformsRequest::handle vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php:40 Illuminate\Foundation\Http\Middleware\TrimStrings::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27 Illuminate\Foundation\Http\Middleware\ValidatePostSize::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php:86 Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/fruitcake/laravel-cors/src/HandleCors.php:38 Fruitcake\Cors\HandleCors::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php:39 Illuminate\Http\Middleware\TrustProxies::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/itsgoingd/clockwork/Clockwork/Support/Laravel/ClockworkMiddleware.php:24 Clockwork\Support\Laravel\ClockworkMiddleware::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline\{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116 Illuminate\Pipeline\Pipeline::then vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:142 Illuminate\Foundation\Http\Kernel::sendRequestThroughRouter vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:111 Illuminate\Foundation\Http\Kernel::handle public/index.php:52 [main]

And here is the example of my overidding update/store functions :

public function update()
{
$response = $this->traitUpdate();
$allValues = request()->all();
// just a call to a function to generate a PDF for example (and the problem is still here without this part)
return $response;
}

public function store()
{
$response = $this->traitStore();
$allValues = request()->all();
// just a call to a function to generate a PDF for example (and the problem is still here without this part)
return $response;
}

And all this work fine in 5.0.15 And not in 5.0.16 and after

Thanks for your help and your amazing job btw!

@ale1981
Copy link

ale1981 commented May 18, 2022

I also had this issue when updating to 5.0.16, again I override the update and store methods. I believe I tracked it down to the getStrippedSaveRequest($request) call in the update and store functions of UpdateOperation and CreateOperation traits.

@jfelixoptimiumnc
Copy link

jfelixoptimiumnc commented May 25, 2022

Hi,

I confirm I have this problem too. Used to work before, don't know since which update it broke.

Even with nothing in the update or store function: Error "Call to a member function only() on array"

   public function store()
    {
        $response = $this->traitStore();

        return $response;
    }

Edited: I confirm that happens on 5.0.18, downgraded to 5.0.14 and it works fine

@pxpm
Copy link
Contributor

pxpm commented May 25, 2022

I am still unable to replicate this, please have a look to see if I am doing something different from you guys: https://recordit.co/XxlnOBtibc

@ale1981
Copy link

ale1981 commented May 30, 2022

I have just upgraded to 5.0.19 to test again. I have tested on a model where I don't even override the store operation and am now getting the error below.

Call to a member function only() on array

originating from the getStrippedSaveRequest function inside Fields.php trait, which is the following line (472);

return $request->only($this->getAllFieldNames());

@ale1981
Copy link

ale1981 commented May 30, 2022

One other difference I can see to your demo is I am using CRUD::field (CrudPanelFacade) to define my fields, you are using $this->crud->addField, not sure if that's making a difference?

I think this is it, after changing the fields to use $this->crud->addField() $request is back to being a Request and not an array.

@cdo9
Copy link

cdo9 commented Jun 2, 2022

Hey, i have the same error, and for me it was because of a relationship field with a belongsToMany relation.

Here is the field :


$this->crud->addField([
    'tab' => 'ingredients',
    'name'  => 'ingredients',
    'label' => 'ingredients',
    'type'  => 'relationship',
    'subfields' => [
        [
            'name'    => 'quantity',
            'type'    => 'text',
            'label'   => 'quantity',
            'wrapper' => ['class' => 'form-group col-md-4'],
        ],
        [
            'label' => 'ingredient_unit',
            'type' => 'select2',
            'name' => 'ingredient_unit_id',
            'model' => 'App\Models\Metas\IngredientUnit',
            'attribute' => 'translated_name',
            'wrapper' => ['class' => 'form-group col-md-4'],
        ],
    ],

    // optional
    'reorder' => 'order',
    'init_rows' => 1, // number of empty rows to be initialized, by default 1
    'min_rows' => 1, // minimum rows allowed, when reached the "delete" buttons will be hidden
    'max_rows' => 50, // maximum rows allowed, when reached the "new item" button will be hidden

]);

Here is my relation :


public function ingredients()
{
    return $this->belongsToMany(Ingredient::class)->using(IngredientRecipe::class)->withPivot('order', 'quantity', 'ingredient_unit_id')->orderBy('order');
}

I have another relationship field with a hasMany relation and he is working fine.

Downgraded to 5.0.14 and everything is working fine again.

If you need more information, feel free to reach me :)

@tabacitu
Copy link
Member

tabacitu commented Jun 3, 2022

Thank you @cdo9 ! belongsToMany, got it!

Can you reproduce now @pxpm ? Seems like a lot of people are getting this error, so we must be missing something here...

@ale1981
Copy link

ale1981 commented Jun 5, 2022

Hey, i have the same error, and for me it was because of a relationship field with a belongsToMany relation.

Here is the field :


$this->crud->addField([
    'tab' => 'ingredients',
    'name'  => 'ingredients',
    'label' => 'ingredients',
    'type'  => 'relationship',
    'subfields' => [
        [
            'name'    => 'quantity',
            'type'    => 'text',
            'label'   => 'quantity',
            'wrapper' => ['class' => 'form-group col-md-4'],
        ],
        [
            'label' => 'ingredient_unit',
            'type' => 'select2',
            'name' => 'ingredient_unit_id',
            'model' => 'App\Models\Metas\IngredientUnit',
            'attribute' => 'translated_name',
            'wrapper' => ['class' => 'form-group col-md-4'],
        ],
    ],

    // optional
    'reorder' => 'order',
    'init_rows' => 1, // number of empty rows to be initialized, by default 1
    'min_rows' => 1, // minimum rows allowed, when reached the "delete" buttons will be hidden
    'max_rows' => 50, // maximum rows allowed, when reached the "new item" button will be hidden

]);

Here is my relation :


public function ingredients()
{
    return $this->belongsToMany(Ingredient::class)->using(IngredientRecipe::class)->withPivot('order', 'quantity', 'ingredient_unit_id')->orderBy('order');
}

I have another relationship field with a hasMany relation and he is working fine.

Downgraded to 5.0.14 and everything is working fine again.

If you need more information, feel free to reach me :)

This isn't the issue for me, I have no BelongsToMany relations and the issue still exists.

@pxpm
Copy link
Contributor

pxpm commented Jun 8, 2022

One other difference I can see to your demo is I am using CRUD::field (CrudPanelFacade) to define my fields, you are using $this->crud->addField, not sure if that's making a difference?

I think this is it, after changing the fields to use $this->crud->addField() $request is back to being a Request and not an array.

This comment stood out for me and I investigated a little further as we had previous issues with defining fields as array or fluently.

I found out an inconsistency when defining ->entity(). Some field callbacks that should be run, and are run when defining as an array, were not running and forcing the developer to manually add the missing attributes.

I didn't get the error you got with only(), that is telling you that the $request is an array, I could not reproduce that...

You can see what I've found and the fix here: #4438

@tabacitu
Copy link
Member

Will review and merge, thank you @pxpm !

Everybody else - quick question. Did everybody here upgrade from v4.1 to v5? Or using a fresh project with v5? I'm wondering if you guys aren't missing an upgrade step or something.

Thank you!

@ale1981
Copy link

ale1981 commented Jun 14, 2022

I did upgrade from v4.1 to v5.0. Which upgrade step are you referring to?

@tabacitu
Copy link
Member

Good question. I think Step 8 and Step 15 in particular could cause this kind of problem, if those changes aren't made.

@madviking
Copy link

madviking commented Jun 15, 2022 via email

@KevinCassier
Copy link
Contributor Author

KevinCassier commented Jun 17, 2022

I started from the 5 directly me too (with pro add-on)

@tabacitu
Copy link
Member

Damn it! Ok then, I don't see how we can debug this further, other than jumping into a call.

Is any of you willing to do a quick call, please, so we can help debug in your particular project, and see where it breaks? It's win-win, I think. If so, please let us know with an email at [email protected] - I'll tag Pedro along so we can coordinate.

Thanks!

Repository owner moved this from In Progress to Done in This week Jun 22, 2022
@tabacitu
Copy link
Member

Hey everybody,

Thank you for your patience on this 🙏

Thanks to a meeting with @cdo9 (thanks again Christophe!), @pxpm was able to finally get to the bottom of this and create PR #4459 . We've just merged it & tagged 5.1.2, which has this fix. So please run a composer update backpack/crud - it should fix it.

Of course, let us know if it doesn't, and we'll reopen.
Cheers!

@tabacitu tabacitu removed this from This week Jun 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Possible Bug A bug that was reported but not confirmed yet. Priority: MUST URGENT
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants