snipe / snipe-it

A free open source IT asset/license management system
https://snipeitapp.com
GNU Affero General Public License v3.0
11.07k stars 3.18k forks source link

Too few arguments to function App\Importer\ItemImporter::fetchManager() Error when importing users from a csv #13850

Closed Azooz2014 closed 11 months ago

Azooz2014 commented 12 months ago

Debug mode

Describe the bug

Hi, I'm trying to import a list of users from a csv file which is following the sample CSVs in the documentation and when it's done there's nothing imported, when i checked the logs i received the following error.

Reproduction steps

  1. Imported csv file
  2. Running the import process
  3. Import process is done and the following message is shown "Your file import is complete, but we did receive an error. This is usually caused by third-party API throttling from a notification webhook (such as Slack) and would not have interfered with the import itself, but you should confirm this. "

Expected behavior

  1. Importing process success
  2. Data imported.

Screenshots

No response

Snipe-IT Version

v6.2.3 - build 11759 (master)

Operating System

Ubuntu 22.04.3 LTS

Web Server

Apache/2.4.52

PHP Version

8.1.2

Operating System

Windows 11 Pro

Browser

Firefox

Version

119.0

Device

No response

Operating System

No response

Browser

No response

Version

No response

Error messages

[2023-11-08 13:43:55] production.ERROR: Too few arguments to function App\Importer\ItemImporter::fetchManager(), 1 passed in /var/www/html/app/Importer/UserImporter.php on line 64 and exactly 2 expected {"userId":1,"exception":"[object] (ArgumentCountError(code: 0): Too few arguments to function App\\Importer\\ItemImporter::fetchManager(), 1 passed in /var/www/html/app/Importer/UserImporter.php on line 64 and exactly 2 expected at /var/www/html/app/Importer/ItemImporter.php:348)#1 /var/www/html/app/Importer/UserImporter.php(31): App\Importer\UserImporter->createUserIfNotExists()
#2 /var/www/html/app/Importer/Importer.php(104): App\Importer\UserImporter->handle()
#3 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php(29): App\Importer\Importer->App\Importer\{closure}()
#4 /var/www/html/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php(442): Illuminate\Database\Connection->transaction()
#5 /var/www/html/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php(261): Illuminate\Database\DatabaseManager->__call()
#6 /var/www/html/app/Importer/Importer.php(111): Illuminate\Support\Facades\Facade::__callStatic()
#7 /var/www/html/app/Http/Requests/ItemImportRequest.php(67): App\Importer\Importer->import()
#8 /var/www/html/app/Http/Controllers/Api/ImportController.php(175): App\Http\Requests\ItemImportRequest->import()
#9 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Controller.php(54): App\Http\Controllers\Api\ImportController->process()
#10 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php(45): Illuminate\Routing\Controller->callAction()
#11 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(262): Illuminate\Routing\ControllerDispatcher->dispatch()
#12 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Route.php(205): Illuminate\Routing\Route->runController()
#13 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(721): Illuminate\Routing\Route->run()
#14 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Routing\Router->Illuminate\Routing\{closure}()
#15 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(127): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#16 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(103): Illuminate\Routing\Middleware\ThrottleRequests->handleRequest()
#17 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Middleware/ThrottleRequests.php(55): Illuminate\Routing\Middleware\ThrottleRequests->handleRequestUsingNamedLimiter()
#18 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Routing\Middleware\ThrottleRequests->handle()
#19 /var/www/html/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php(44): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#20 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Auth\Middleware\Authenticate->handle()
#21 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#22 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(723): Illuminate\Pipeline\Pipeline->then()
#23 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(698): Illuminate\Routing\Router->runRouteWithinStack()
#24 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(662): Illuminate\Routing\Router->runRoute()
#25 /var/www/html/vendor/laravel/framework/src/Illuminate/Routing/Router.php(651): Illuminate\Routing\Router->dispatchToRoute()
#26 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(167): Illuminate\Routing\Router->dispatch()
#27 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(128): Illuminate\Foundation\Http\Kernel->Illuminate\Foundation\Http\{closure}()
#28 /var/www/html/vendor/livewire/livewire/src/DisableBrowserCache.php(19): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#29 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Livewire\DisableBrowserCache->handle()
#30 /var/www/html/vendor/barryvdh/laravel-debugbar/src/Middleware/InjectDebugbar.php(66): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#31 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Barryvdh\Debugbar\Middleware\InjectDebugbar->handle()
#32 /var/www/html/vendor/fruitcake/laravel-cors/src/HandleCors.php(52): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#33 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fruitcake\Cors\HandleCors->handle()
#34 /var/www/html/app/Http/Middleware/PreventBackHistory.php(23): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#35 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\PreventBackHistory->handle()
#36 /var/www/html/app/Http/Middleware/SecurityHeaders.php(26): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#37 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\SecurityHeaders->handle()
#38 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php(21): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#39 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php(31): Illuminate\Foundation\Http\Middleware\TransformsRequest->handle()
#40 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull->handle()
#41 /var/www/html/app/Http/Middleware/CheckForDebug.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#42 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\CheckForDebug->handle()
#43 /var/www/html/app/Http/Middleware/CheckForSetup.php(25): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#44 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\CheckForSetup->handle()
#45 /var/www/html/vendor/fideloper/proxy/src/TrustProxies.php(57): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#46 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Fideloper\Proxy\TrustProxies->handle()
#47 /var/www/html/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php(49): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#48 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\View\Middleware\ShareErrorsFromSession->handle()
#49 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(121): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#50 /var/www/html/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php(64): Illuminate\Session\Middleware\StartSession->handleStatefulRequest()
#51 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Session\Middleware\StartSession->handle()
#52 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php(86): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#53 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance->handle()
#54 /var/www/html/app/Http/Middleware/NoSessionStore.php(28): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#55 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(167): App\Http\Middleware\NoSessionStore->handle()
#56 /var/www/html/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php(103): Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}()
#57 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(142): Illuminate\Pipeline\Pipeline->then()
#58 /var/www/html/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php(111): Illuminate\Foundation\Http\Kernel->sendRequestThroughRouter()
#59 /var/www/html/public/index.php(52): Illuminate\Foundation\Http\Kernel->handle()
#60 {main}

Additional context

Fresh install from latest docker image

welcome[bot] commented 12 months ago

👋 Thanks for opening your first issue here! If you're reporting a 🐞 bug, please make sure you include steps to reproduce it. We get a lot of issues on this repo, so please be patient and we will get back to you as soon as we can.

Azooz2014 commented 11 months ago

Bump and Updated title to reflect the exact error more accurately.

Azooz2014 commented 11 months ago

@snipe I Found a bug in the UserImporter Class and i've fixed it, can i create a pull request?

inietov commented 11 months ago

@Azooz2014 Not Snipe (thankfully for her tho), but I was looking into https://github.com/snipe/snipe-it/issues/13860 and appears to be the same issue and I was not able to reproduce it in my local instance. But yeah, If you found the issue we are happy to discuss it more in a PR. Also you are gonna be helping another Snipe-IT user, and that is always welcomed!!

thehamzajunaid commented 11 months ago

@Azooz2014 Not Snipe (thankfully for her tho), but I was looking into #13860 and appears to be the same issue and I was not able to reproduce it in my local instance. But yeah, If you found the issue we are happy to discuss it more in a PR. Also you are gonna be helping another Snipe-IT user, and that is always welcomed!!

Hi, coming from #13860. Have you guys solved the issue?

Azooz2014 commented 11 months ago

@inietov The problem was the call of fetchManager() function in the UserImporter Class where the trim function inside the passed arguments was used in a wrong way which caused an ArugmentCount Exception to be thrown thinking that only 1 argument was passed but in fact 2 arguments were passed. I forked the master branch and inspected the code but everything looked correct in there so maybe this strange bug was packaged into the latest docker image by accident or something.

The Build version i have from the docker is v6.2.3 - build 11759 (master) and the original code of fetchManager() function in the UserImporter Class is as below:-

$this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name')));

The way i fixed it is by modifying fetchManager() function in the UserImporter Class inside the running docker container to be as below:-

$this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_first_name')), trim($this->findCsvMatch($row, 'manager_last_name')));

@thehamzajunaid you can try the above way in your running docker container.

snipe commented 11 months ago

@Azooz2014 - sure, we'd take a PR for this

Azooz2014 commented 11 months ago

@snipe Under which branch should I create the PR under? I've checked the master branch but the code seemed ok in there and didn't have the bug i mentioned.

snipe commented 11 months ago

master and develop are at parity right now (and usually are), but all development should be done on develop for testing.

thehamzajunaid commented 11 months ago

@inietov The problem was the call of fetchManager() function in the UserImporter Class where the trim function inside the passed arguments was used in a wrong way which caused an ArugmentCount Exception to be thrown thinking that only 1 argument was passed but in fact 2 arguments were passed. I forked the master branch and inspected the code but everything looked correct in there so maybe this strange bug was packaged into the latest docker image by accident or something.

The Build version i have from the docker is v6.2.3 - build 11759 (master) and the original code of fetchManager() function in the UserImporter Class is as below:-

$this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_first_name'), $this->findCsvMatch($row, 'manager_last_name')));

The way i fixed it is by modifying fetchManager() function in the UserImporter Class inside the running docker container to be as below:-

$this->item['manager_id'] = $this->fetchManager(trim($this->findCsvMatch($row, 'manager_first_name')), trim($this->findCsvMatch($row, 'manager_last_name')));

@thehamzajunaid you can try the above way in your running docker container.

Hi Azooz, can you please share the format of the CSV that you are importing.

Azooz2014 commented 11 months ago

I followed the same format mentioned in snipe-it documentation

thehamzajunaid commented 11 months ago

image

Can you please confirm if this is what your csv titles look like? After importing the csv I'm selecting the "User" import option and all the checkboxes are empty.