magento2-connector-community
magento2-connector-community copied to clipboard
SQLSTATE[21000]: Cardinality violation
Environment and configuration
- Connector 103.0.6
- Magento 2.4.4
- Akeneo 6.0.37
Steps to reproduce
- Import options (cron or UI)
Expected result
- 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" )
Looks like the connector is inserting empty rows in the attribute options list.
And duplicates
empty rows happens when you schedule imports.
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:
- Run
php bin/magento akeneo_connector:import -vvv --code=optionvia the command line. - It may or may not throw the exception reported by @oefterdal , but the
akeneo_connector_entitiestable 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
- Find a duplicate
codeinakeneo_connector_entitiesthat has a dash ('-') in it that is not at the end or the beginning of the string (e.g.,test-code). - Insert a new record into
tmp_akeneo_connector_entities_optiontable 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.
- 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.
@cmastromonaco I am having the same issue. Did you find a way to work around it?
@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.