akeneo / magento2-connector-community

Akeneo Connector for Magento 2
Open Software License 3.0
83 stars 89 forks source link

SQLSTATE[21000]: Cardinality violation #610

Open oefterdal opened 2 years ago

oefterdal commented 2 years ago

Environment and configuration

  1. Connector 103.0.6
  2. Magento 2.4.4
  3. Akeneo 6.0.37

Steps to reproduce

  1. Import options (cron or UI)

Expected result

  1. Success

Actual result

option [00:00:04] Start import [00:00:04] Import ID : 631a820413417 [00:00:04] Create temporary table [00:00:04] completed Path to log file : /var/log/akeneo_connector/option-import.log [00:00:04] Fill temporary table [00:00:07] 795 line(s) found [00:00:07] Check already imported entities [00:00:07] completed [00:00:07] Match code with Magento ID [00:00:07] SQLSTATE[21000]: Cardinality violation: 1242 Subquery returns more than 1 row, query was: UPDATE tmp_akeneo_connector_entities_option t SET _entity_id = ( SELECT entity_id FROM akeneo_connector_entities c WHERE CONCAT(t.attribute, "-", t.code) = c.code AND c.import = "option" )

oefterdal commented 2 years ago

Looks like the connector is inserting empty rows in the attribute options list.

oefterdal commented 2 years ago

And duplicates

oefterdal commented 2 years ago

empty rows happens when you schedule imports.

cmastromonaco commented 1 year ago

I am getting the exact same issue and am in urgent need of a solution.

Versions:

Magento: 2.4.5 Akeneo Connector: 103.0.6 Akeneo: 3.0.45 & 4.0.126

The issue is actually the conjunction of two events (for me at least): the akeneo_connector_entities table having duplicate code values and a attribute + code pair (concatenated with a dash '-') from the tmp_akeneo_connector_entities_option table matching one of those aforesaid duplicate codes. I verified that even deleting the duplicates from akeneo_connector_entities does not help, as re-running the option import from the command line will re-populate those duplicates.

Steps to reproduce:

  1. Run php bin/magento akeneo_connector:import -vvv --code=option via the command line.
  2. It may or may not throw the exception reported by @oefterdal , but the akeneo_connector_entities table will now contain duplicates. I verified by running the following query afterwards:
SELECT *, COUNT(code) as c FROM `akeneo_connector_entities`
WHERE import = 'option'
GROUP BY code HAVING c > 1
  1. Find a duplicate code in akeneo_connector_entities that has a dash ('-') in it that is not at the end or the beginning of the string (e.g., test-code).
  2. Insert a new record into tmp_akeneo_connector_entities_option table where:

a) The code is the second half (split by the dash) of the code found in step 3 (from akeneo_connector_entities) (e.g., code). b) The attribute is the first half (split by the dash) of the code found in step 3 (ditto) (e.g., test). c) The _entity_id is set to the entity_id corresponding the code found in step 3 (ditto) (e.g., 1). d) All other columns can be left as NULL.

  1. Run the UPDATE query manually and slightly adjust it to only run for that _entity_id (as found in step 4 part c):
UPDATE `tmp_akeneo_connector_entities_option` t
SET `_entity_id` = (
    SELECT `entity_id` FROM `akeneo_connector_entities` c
    WHERE CONCAT(t.`attribute`, "-", t.`code`) = c.`code`
        AND c.`import` = "option"
        AND t.`_entity_id` = "1" -- I ADDED THIS IN TO LIMIT TO THAT ONE RECORD IN TMP TABLE
)

Result: #1242 - Subquery returns more than 1 row.

SIDENOTE: I understand that the point of the UPDATE query is to actually properly set the _entity_id, but I preemptively set it to be able to isolate which records are getting pulled (to, in turn, identify the issue).

@oefterdal Have you discovered a fix to this? I am currently trying to upgrade to 103.0.6 but this issue is making it unusable.

mudgett06 commented 1 year ago

@cmastromonaco I am having the same issue. Did you find a way to work around it?

cmastromonaco commented 1 year ago

@cmastromonaco I am having the same issue. Did you find a way to work around it?

@mudgett06 Unfortunately, I have not as of yet; but I will let you know if I find out one.