Mautic Community Forums

EntityManager is closed / Import contacts page is broken

Your software
My Mautic version is: 2.15.2
My PHP version is: 7.1.30

Your problem
My problem is:

Hey all, I’m having an issue with importing on a relatively new Mautic install. After trying to import a large CSV (~20k contacts), the import hung. I allowed it to go to background and figured the cron job would pick it up, but it didn’t after 6 hours. I ran the mautic:import job manually and got the following error:

Import 11 with 247 rows is starting.
34/247 [===>------------------------] 13%Import failed. Reason: There was a database error: The EntityManager is closed… The import was set to delayed state and will be imported later.

Further, in the Mautic logs I see a related error:
autic.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: “The EntityManager is closed.” at /opt/bitnami/apps/mautic/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 144

At this point, Mautic will not even load the “import new contacts” page — just does nothing after I click to import. If I go to /s/contacts/import/new directly, I get the 500 Internal Server Error “Uh oh! I think I broke it” error message.

Any clues on how I might go about fixing this?

These errors are showing in the log:
mautic.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: “The EntityManager is closed.” at /opt/bitnami/apps/mautic/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 144 {“exception”:"[object] (Doctrine\ORM\ORMException(code: 0): The EntityManager is closed. at /opt/bitnami/apps/mautic/htdocs/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:144)"}

Steps I have tried to fix the problem:
Restarted server, Googled extensively

I think this is actually “I’ve run out of memory during the import and lost my database connection”.

The import was set to delayed state and will be imported later.

I have found that if an import task fails with an error, such as EntityManager is closed, you will need to Unpublish/Republish the task. I think the only scenario that actually “imports later” is when the batch limit is reached without errors, and the next cronjob picks up from there.

Try https://example.com/s/contacts/import/1 where you can Unpublish/Publish the CSV file.
Thankfully, re-importing the same file is OK. Duplicates are handled.

Also, see if you can lint the datafile ie confirm the correct number of colums for each line.

I use the Rainbow CSV extension in VS Code to assist.

FYI these are my import CSV notes

:gear: IMPORT

Background process to import contacts from CSV files

  • :keyboard: Command line
    mautic:import --limit=400 --quiet

  • :clock1: Schedule
    every 6 minutes

I would also advise splitting the CSV file into 1000 contact chunks.

:bulb: ProTip

:penguin: If using a Linux system, see the GNU parallel command. (sudo apt install parallel)

cat big_contact_list.csv | parallel --header : --pipe -N 1000 'cat > split_list_part{#}.csv'

This will generate files:

split_list_part1.csv
split_list_part2.csv

split_list_part10.csv

$ console mautic:import
Import 2 with 1001 rows is starting.
 1001/1001 [============================] 100%
1001 lines were processed, 988 items created, 12 items updated, 1 items ignored in 84.83 s

Regards,

Virgil
:australia:

1 Like

I can second this bug report. I am using Mautic 2.15.3 and PHP 7.2.27, and have been trying to import a CSV file, but also received the reported log entry:

[2020-01-31 15:12:46] mautic.CRITICAL: Uncaught PHP Exception Doctrine\ORM\ORMException: “The EntityManager is closed.” at (…)/mautic/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php line 144 {“exception”:"[object] (Doctrine\ORM\ORMException(code: 0): The EntityManager is closed. at (…)/mautic/vendor/doctrine/orm/lib/Doctrine/ORM/ORMException.php:144)"}

with the import page hanging indefinitely. (Unpublishing and republishing the task, as suggested above did not help.)

However, in my case I’m absolutely certain that it has nothing to do with memory. I’m using a memory_limit of 512M and and an upload_max_filesize of 64M. The file in question has only 2 lines and 2 columns, resulting in 153 bytes total. (I stripped the original file down to this minimal size to check, if the problem is related to size.)

I noticed, however, that the problem seems to be somehow related to one of the columns being imported into a custom field of type Text Area, as all other – even much bigger CSV files – are imported without any problems. (By the way: The file is UTF8.)

Any ideas? Any help would be much appreciated.
Thank you very much in advance.
Marcus