1

I'm trying to import products by CSV and I got a lot of additional_attributes, whereas one of them seems to break the import and I get the never ending "please wait" wheel.

here's the part of the csv that is causing the error, without it, it works. It's the field additional_attributes:

apg_product_references="<ol><li>Association between obesity and asthma in the elderly population: potential roles of abdominal subcutaneous adiposity and sarcopenia: W.J. Song, et al.; Ann. Allergy Asthma Immunol. <strong>109,</strong> 243 (2012)</li>
<li>Omentin-1, visfatin and adiponectin levels in relation to bone mineral density in Iranian postmenopausal women: M. Tohidi, et al.; Bone <strong>51,</strong> 876 (2012)</li>
<li>A 12-week after-school physical activity programme improves endothelial cell function in overweight and obese children: a randomised controlled study: J.H. Park, et al.; BMC Pediatr. <strong>12,</strong> 111 (2012)</li>
<li>Adiponectin, leptin and lipid profiles evaluation in oral contraceptive pill consumers: S. Fallah, et al.; Arch. Gynecol. Obstet. <strong>285, </strong>1747 (2012)</li>
<li>Dietary intervention induces flow of changes within biomarkers of lipids, inflammation, liver enzymes, and glycemic control: R. Golan, et al.; Nutrition <strong>28,</strong> 131 (2012)</li>
<li>Metabolic Syndrome is Associated with Low Adiponectin Level and Increased Insulin Resistance in Apparently Healthy Koreans: K.H. Yoo, et al.; Korean J. Obes. <strong>21,</strong> 175 (2012)</li>
<li>Gastrectomy for Early Gastric Cancer is Associated with Decreased Cardiovascular Mortality in Association with Postsurgical Metabolic Changes:Y.H. Lee, et al.; Ann. Surg. Oncol. <strong>20,</strong> 1250 (2012)</li>
<li>Metabolic Syndrome is Associated with Low Adiponectin Level and Increased Insulin Resistance in Apparently Healthy Koreans: K.H. Yoo, et al.; Korean J. Obes. <strong>21,</strong> 175 (2012)</li><li>Dietary intervention induces flow of changes within biomarkers of lipids, inflammation, liver enzymes, and glycemic control: R. Golan, et al.; Nutrition <strong>28,</strong> 131 (2012)</li>
<li>Metabolic Syndrome is Associated with Low Adiponectin Level and Increased Insulin Resistance in Apparently Healthy Koreans: K.H. Yoo, et al.; Korean J. Obes. <strong>21,</strong> 175 (2012)</li>
</ol>"

If I only try to import the first 6 lines, it works, but it seems to be stuck if there are more than 6 lines.

The console in chrome shows the following: net::ERR_EMPTY_RESPONSE -> validation.js:168 enter image description here

I only try to import one product, so it shouldn't be a problem with too much data, it just seems like it's a problem with the html code for that attribute.

Is there something like a max length for custom attributes on import that could cause this problem?

Update: If I add the same HTML content via magento backend and export it, everything looks alright, so it's only a problem on import.

2 Answers 2

0

If you believe this is a character length issue i'd look in the eav_attribute table for your attribute code. If the backend_type is varchar there is a character limit of 255. The product import itself does not have a character limit.

This to me sounds more like an issue with the CSV itself. You have a lot of commas and semi-colons which tend to cause issues with CSV imports. You should open the CSV in a plain text editor to see if there are any strange characters around the 6th line.

I've found the best way to prevent CSV import issues is to use Open Office (https://www.openoffice.org/). Other Programmes such as Excel and Numbers tend to add unexpected encoding to your CSV.

When saving with Open Office use 'Save As' and check the 'Edit Filter Settings' check box. In the next step it will allow you to quote all text cells which i've found useful in preventing import issues.

Just a brain dump. Hope it helps.

1
  • Thanks for the response! The length shouldn't be the problem, because I can add all the content via magento admin and it works. I'm using LibreOffice for that same reason with the encoding and seems to work well, but I still guess it has to do something with import attribute length, because even if I switch up the lines a little bit, it still fails. If I compare the exported content with my content to import, I see no difference in csv, so the format should be right. Any other hints?
    – NthDegree
    Jun 22, 2017 at 12:00
0

I were in a similar case, and here's what I found out

Explaination :

Since the content can be added via magento backend it's not a specific type max length issue.

Now, as you suspected it might have something to do with length but not directly since other simpler and longer strings parse fine (in my case),

the products import as of Magento 2.1.10 happens here : \Magento\CatalogImportExport\Model\Import\Product

and additional_attributes get parsed in this method (Fields enclosure checked in import form):

private function parseAttributesWithWrappedValues($attributesData)
{
    $attributes = [];
    preg_match_all('~((?:[a-z0-9_])+)="((?:[^"]|""|"' . $this->getMultiLineSeparatorForRegexp() . '")+)"+~',
        $attributesData,
        $matches
    );

    foreach ($matches[1] as $i => $attributeCode) {
        $attribute = $this->retrieveAttributeByCode($attributeCode);
        $value = 'multiselect' != $attribute->getFrontendInput()
            ? str_replace('""', '"', $matches[2][$i])
            : '"' . $matches[2][$i] . '"';
        $attributes[$attributeCode] = $value;
    }
    return $attributes;
}

preg_match_all puts the results in $matches like this :

[
0 => [
    0 => 'attribute0="<div class=""row"">html content</div>"',
    1 => 'attribute1="option1"|"option2"|"option51"',
    2 => 'attribute2="Yes"'
],
1 => [
    0 => 'attribute0',
    1 => 'attribute1',
    2 => 'attribute2'
],
2 => [
    0 => '<div class=""row"">html content</div>',
    1 => 'option1"|"option2"|"option51',
    2 => 'Yes'
],

]

but for the problematic string it returns a silent null not knowing whether it's a non-match or an error, by printing preg_last_error() (as suggested in this stackoverflow answer) I got a PREG_JIT_STACKLIMIT_ERROR (more info)

Solution :

For now I just found that by disabling JIT in PCRE module :

ini_set('pcre.jit', 0);

it parses fine.

It could be the other PCRE setting (pcre.backtrack_limit or recursion_limit)

Hope it helps others

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.