Laravel-Backpack / devtools-issues

Bug reports and feature requests for our closed-source DevTools package
4 stars 1 forks source link

[Bug] Trying to access array offset on value of type null #57

Closed lukepower closed 1 year ago

lukepower commented 1 year ago

Bug report

What I did

After following the automatic installation, when trying to create a new model (even without adding any particular filed), when saving I end up with a 500 error.

'Trying to access array offset on value of type null'

What I expected to happen

The new model to be at least saved.

What happened

Got a 500 error Trying to access array offset on value of type null

What I've already tried to fix it

Tried to simplify the new model to the bare minimum. Also, restarting Mysql or php artisan serve, as well as a composer update. No change.

Backpack, Laravel, PHP, DB version

When I run php artisan backpack:version the output is:

PHP VERSION:

PHP 8.1.2 (cli) (built: Jan 19 2022 10:18:23) (ZTS Visual C++ 2019 x64) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans

LARAVEL VERSION:

v9.48.0@c78ae7aeb0cbcb1a205050d3592247ba07f5b711

BACKPACK PACKAGE VERSIONS:

backpack/crud: 5.0.19 backpack/pagemanager: 3.0.11 backpack/permissionmanager: 6.0.15 backpack/pro: 1.0.18 backpack/generators: v3.1.13

Operating System and Server Setup

I encountered the problem above on my Windows 10 machine, and my web server is set up using XAMPP.

pxpm commented 1 year ago

Hello @lukepower thanks for the report šŸ™

I will need a bit more to try to figure out what's going on. Can you share with me the flare page error, or post some more details about the error ?

You can probably find more details on storage/logs/laravel.log file.

Any chance you could update backpack dependencies, so that we make sure we are not talking about some issue that we had previously fixed ? We are currently on Backpack 5.4, it should be a non-breaking update šŸ‘

Don't forget to republish assets after update with: php artisan backpack:publish-assets.

Cheers

lukepower commented 1 year ago

Error is this: '{ "class": "ErrorException", "message": "Trying to access array offset on value of type null", "code": 0, "file": "F:\Programming\new-remote-skygems\vendor\laravel-shift\blueprint\src\Tracer.php:120", "trace": [ "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Foundation\Bootstrap\HandleExceptions.php:266", "F:\Programming\new-remote-skygems\vendor\laravel-shift\blueprint\src\Tracer.php:120", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Collections\Traits\EnumeratesValues.php:236", "F:\Programming\new-remote-skygems\vendor\laravel-shift\blueprint\src\Tracer.php:121", "F:\Programming\new-remote-skygems\vendor\laravel-shift\blueprint\src\Tracer.php:33", "F:\Programming\new-remote-skygems\vendor\laravel-shift\blueprint\src\Commands\TraceCommand.php:51", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Container\Util.php:41", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:93", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:37", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Container\Container.php:663", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Console\Command.php:182", "F:\Programming\new-remote-skygems\vendor\symfony\console\Command\Command.php:312", "F:\Programming\new-remote-skygems\vendor\laravel\framework\src\Illuminate\Console\Command.php:152", "F:\Programming\new-remote-skygems\vendor\symfony\console\Application.php:1022", "F:\'

As for updating, how am I supposed to be able to force CRUD 5.4? Seems that while composer selects it, it is not being installed...

pxpm commented 1 year ago

Hey @lukepower

You can do a "composer update backpack/crud".

What does it say? Any errors?

If you got any errors please post them here so that I can have a look at it to help you.

You can also do a "composer why backpack/crud" to check if some of your other packages is forcing the 5.0 version.

Let me know.

lukepower commented 1 year ago

`PS F:\Programming\new-remote-skygems> composer require backpack/crud:5.4.0 --with-all-dependencies Info from https://repo.packagist.org: #StandWithUkraine ./composer.json has been updated Running composer update backpack/crud --with-all-dependencies Loading composer repositories with package information Updating dependencies Your requirements could not be resolved to an installable set of packages.

Problem 1

Installation failed, reverting ./composer.json and ./composer.lock to their original content.`

lukepower commented 1 year ago

And:

laravel/laravel dev-master requires backpack/crud (^5.4)
backpack/devtools 1.3.0 requires backpack/crud (^5.3)
backpack/generators 3.3.12 requires backpack/crud (^5.3.11) backpack/pagemanager 3.0.11 requires backpack/crud (^4.0|^5.0) backpack/permissionmanager 6.0.15 requires backpack/crud (^5.0) backpack/pro 1.5.0 requires backpack/crud (^5.4.9)

pxpm commented 1 year ago

Hey @lukepower, try updating the following in your composer.json:

        "backpack/crud": "^5.4",
        "backpack/permissionmanager": "^6.0",
        "backpack/pagemanager": "^3.0",
        "backpack/pro": "^1.5"

Run composer update again. Let me know if still some error in your output.

Cheers

lukepower commented 1 year ago

Thats exactly what I currently have: "backpack/crud": "^5.4", "backpack/pagemanager": "^3.0", "backpack/permissionmanager": "^6.0", "backpack/pro": "^1.5.0",

lukepower commented 1 year ago

@pxpm I can uninstall pagemanager as I am not using it anymore, but permissionmanager seems to conflict with the version...

lukepower commented 1 year ago

Actually, digging further: I have been able to install the 5.4 version package: laravel/laravel dev-master requires backpack/crud (^5.4)
backpack/devtools 1.3.0 requires backpack/crud (^5.3)
backpack/generators 3.3.12 requires backpack/crud (^5.3.11) backpack/pro 1.5.0 requires backpack/crud (^5.4.9)

However, php artisan backpack:version Still returns: backpack/crud: 5.0.19 backpack/pagemanager: 3.0.11 backpack/permissionmanager: 6.0.15 backpack/pro: 1.0.18 backpack/generators: v3.1.13

pxpm commented 1 year ago

Hey @lukepower thanks for getting back with an update.

Can you then try: composer clear-cache , composer dump-autoload, php artisan cache:clear and check again.

If the problem persists I would advise you to try to install one by one, starting: crud -> pro -> generators -> permissionmanager

Let me know how it goes.

Cheers

lukepower commented 1 year ago

nothing... Is there a practical way of determining the effective version from the source files?

pxpm commented 1 year ago

You should be able to check that in your composer.lock file. use some text editor to search for backpack/crud in that file.

lukepower commented 1 year ago

"name": "backpack/crud", "version": "5.4.15", "source": { "type": "git", "url": "https://github.com/Laravel-Backpack/CRUD.git", "reference": "146a08082ebf3ad2f88df3e18c9735ad57ff19e5" },

So, I deleted the whole "backpack" folder in "vendor/":


But still: php artisan backpack:version

PHP VERSION:

PHP 8.1.2 (cli) (built: Jan 19 2022 10:18:23) (ZTS Visual C++ 2019 x64) Copyright (c) The PHP Group Zend Engine v4.1.2, Copyright (c) Zend Technologies with Xdebug v3.1.2, Copyright (c) 2002-2021, by Derick Rethans

LARAVEL VERSION:

v9.48.0@c78ae7aeb0cbcb1a205050d3592247ba07f5b711

BACKPACK PACKAGE VERSIONS:

backpack/crud: 5.0.19 backpack/pagemanager: 3.0.11 backpack/permissionmanager: 6.0.15 backpack/pro: 1.0.18 backpack/generators: v3.1.13

lukepower commented 1 year ago

composer show: asm89/stack-cors v2.1.1 Cross-origin resource sharing library and stack middleware aws/aws-crt-php v1.0.2 AWS Common Runtime for PHP aws/aws-sdk-php 3.257.4 AWS SDK for PHP - Use Amazon Web Services in your PHP project backpack/crud 5.4.15 Quickly build an admin interfaces using Laravel, CoreUI, Bootstrap and jQuery. backpack/devtools 1.3.0 An admin UI for generating migrations, models and CRUDs backpack/generators 3.3.12 Generate files for laravel projects backpack/pro 1.5.0 Operations, Fields, Columns, Filters and Widgets for not-so-simple admin panels. balping/json-raw-encoder v1.0.1 Encode arrays to json with raw JS objects (eg. callbacks) in them

So, it seems the versions are latest already?

lukepower commented 1 year ago

So, I went digging a little deeper.

It seems that the error happens on line 33 of laravel-shift\blueprint\src\Tracer.php, specifically later on line 117: $column->getType() instanceof \Blueprint\EnumType)->each(function (&$column, $key) use ($definitions)

the .each function is throwing an exception about an empty array. Well... That's what I can find out :)

lukepower commented 1 year ago

OK, have fixed it, sort of. Seems to be an issue either in the Traver.php, or upstream. I inserted a check for a null value on line 121:

if ($definition != null) { $column->options = \Blueprint\EnumType::extractOptions($definition['Type']); }

pxpm commented 1 year ago

I am not sure there is a bug there in code. Otherwise I would getting it too, and other people using devtools.

I think the problem could lie somewhere between the db engine and/or the xampp process.

We had some issues a few time ago while developing using xampp, we even had a troubleshooting for a known problem, not the same as you report, but it could be the same cause, we just didn't get it by then.

I now use Laragon (not affiliated, just happy user), and can't look back at using xampp again šŸ‘€

I will copy paste here the note we had in previous versions:

NOTE for XAMPP / WAMP installations

If after creating the migration the tool ask you to run composer dump-autoload is very likely that your are running the apache http server as a service and don't have the right privilegesĀ to interact with the operating system, preventing DevTools from automatically calling composer dump-autoload after migration is created.

If you get the error, the first thing you need to do is manually calling composer dump-autoload. And then follow the instructions down here.

If you know that your http server is running as a service beforehand please also do one of the following beforeĀ creating migrations.

There are two options: a) remove service and start it manually; b) temporary stop the service and start manually;

a) remove service and start apache manually

XAMPP - Untick the service checkbox for apache and manually start it.

image

WAMP - click uninstall service and then manually start apache.

image

b) temporary stop the service and start manually

NOTE: automating stop/start service

You can create a little .bat script to help automate this task. Here is one example for wamp64 on Windows 10:

taskkill /F /FI "SERVICES eq wampapache64"
start /d "c:\wamp64\bin\apache\apache2.4.46\bin\" httpd.exe

Save this as restart_apache.bat in your desktop for example and then run as administrator.This will stop the wampapache64 service and then it starts apache as a system application.

You can change the service name and the httpd.exe directory to match your setup and this should work for any wamp/xampp versions.

pxpm commented 1 year ago

Closing, hope you had this sorted out, if not, please re-open!

Cheers