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] Error import: object beginTransaction #1998

Closed
3 tasks done
NHuebner1983 opened this issue Jan 16, 2019 · 14 comments
Closed
3 tasks done

[BUG] Error import: object beginTransaction #1998

NHuebner1983 opened this issue Jan 16, 2019 · 14 comments

Comments

@NHuebner1983
Copy link

Prerequisites

  • Able to reproduce the behaviour outside of your code, the problem is isolated to Laravel Excel.
  • Checked that your issue isn't already filed.
  • Checked if no PR was submitted that fixes this problem.

Versions

  • PHP version: 7.2
  • Laravel version: 5.7.17
  • Package version: 3.1.3

Description

I have created the import object class and specified the Concerns of ToCollection. Upon performing Excel::import, I receive an error shown in Actual Behavior below.

Steps to Reproduce

Do not use a transactional database. We use MongoDB.

Aside from that, Model importing was not specified and the package should not be doing any database preparation, that should be handled through events by the developer.

Expected behavior:

dd of the collection rows.

Actual behavior:

1) Tests\Unit\Services\Websites\WebsiteCredentialsImportServiceTest::testImportTabDelimited
Error: Call to a member function beginTransaction() on null

/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:109
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:93
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:23
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Database/DatabaseManager.php:327
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/var/www/vhosts/website.local/vendor/maatwebsite/excel/src/Reader.php:96
/var/www/vhosts/website.local/vendor/maatwebsite/excel/src/Excel.php:120
/var/www/vhosts/website.local/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:223
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:198
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:182
/var/www/vhosts/website.local/app/Services/Websites/WebsiteCredentialsImportService.php:122
/var/www/vhosts/website.local/tests/Unit/Services/Websites/WebsiteCredentialsImportServiceTest.php:25

Additional Information

<?php

namespace App\Imports\Websites;

use Illuminate\Support\Collection;
use Maatwebsite\Excel\Concerns\ToCollection;

/**
 * Class WebsiteCredentialsImport
 *
 * @package App\Imports\Websites
 */
class WebsiteCredentialsImport implements ToCollection
{
    public function collection(Collection $rows)
    {
        dd(['COLLECTION' => $rows]);
    }
}
        $collection = Excel::import(
            new WebsiteCredentialsImport,
            $this->file_name,
            null,
            $this->reader_type
        );
@patrickbrouwers
Copy link
Member

We use the database transactions for validation and batch inserts. They are quite vital for the Eloquent/Laravel-DB users. Happy to merge a PR that gives a config option to disable it for users that use .e.g Mongo

@patrickbrouwers
Copy link
Member

Next version will have a setting to disable Laravel-DB transactions + a way to add custom transaction handlers

@realtebo
Copy link

Hi !

I'm in the very exact situation: I need to NOT save read data, and I am using Mongo.

Could you point me please to the code that disable transactions?

@GlennM
Copy link
Contributor

GlennM commented Feb 28, 2019

Hi !

I'm in the very exact situation: I need to NOT save read data, and I am using Mongo.

Could you point me please to the code that disable transactions?

13374da#diff-19c82312ec0dbaba6a8c595db14fa56f

@patrickbrouwers
Copy link
Member

Relevant documentation section: https://docs.laravel-excel.com/3.1/imports/validation.html#disable-transactions

@spawn81
Copy link

spawn81 commented Jul 7, 2019

Hi, I'm in the same situation: I have to read an excel file and I need to store it in mongodb.
I've read the fix and the error I have now is:
"Unable to resolve NULL driver for [Maatwebsite\Excel\Transactions\TransactionManager]."
Do you have any idea how to solve it?
Thank you for the great package.

edit: I used the import to collection and it works, but I still don't knonw why the import toModel breaks

@patrickbrouwers
Copy link
Member

Because Collection doesn't use transactions. Please refer to my previous comment, it explains how to disable transactions.

@spawn81
Copy link

spawn81 commented Jul 7, 2019

Because Collection doesn't use transactions. Please refer to my previous comment, it explains how to disable transactions.

Hi, thank you for your quick reply.
I did read your comment, that's why I recieved the "Unable to resolve NULL driver for [Maatwebsite\Excel\Transactions\TransactionManager]." error.
So I switched to collection

@patrickbrouwers
Copy link
Member

You are probably typing something wrong in your config then. NULL doesn't sound like a valid driver. 'null' (note that it is a string) is.

@JignasaSutariya
Copy link

I also have the same situation, I got the solution on https://docs.laravel-excel.com/3.1/imports/validation.html#disable-transactions
But, I don't know how to create Custom transaction handlers and where to use it

@david-navarro
Copy link

@gcjbr
Copy link

gcjbr commented Oct 3, 2019

Maybe you guys are having the same issue I did at #2384

Maybe my solution would work for you, try a:

php artisan config:clear

Sometimes, specially when updating a package, Laravel won't clean the cache and your package won't find the config files. Thus, the driver will be always NULL and fail.

@amjadArqan
Copy link

Maybe you guys are having the same issue I did at #2384

Maybe my solution would work for you, try a:

php artisan config:clear

Sometimes, specially when updating a package, Laravel won't clean the cache and your package won't find the config files. Thus, the driver will be always NULL and fail.

Best Answer

@HoangKimThanh
Copy link

@patrickbrouwers I use Laravel 8 and MongoDB. I have config 'handler' => 'null' and try 'php artisan config:clear' but it doesn't import excel file to my database

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

No branches or pull requests

10 participants