Indicia-Team / warehouse

GNU General Public License v3.0
5 stars 3 forks source link

Error updating multi-value termlist attributes from file import #449

Closed JimBacon closed 2 years ago

JimBacon commented 2 years ago

If an occurrence has a multi-value attribute whose value is selected from a termlist and that occurrence is updated via file import, then an error is logged and the import fails.

The error is

2022-07-26 13:21:57 +00:00 --- error: #2: Error converted to exception. pg_query(): Query failed: ERROR:  invalid input syntax for type integer: "fk_7"
LINE 1: ...ated_by_id = 1 WHERE occurrence_attribute_id = 'fk_7' AND...
                                                             ^ at line 86 in file /var/www/html/system/libraries/drivers/Database/Pgsql.php
2022-07-26 13:21:57 +00:00 --- debug: Stack trace:
    Unknown file - line Unknown - indicia_error_handler
    /var/www/html/system/libraries/drivers/Database/Pgsql.php - line 86 - pg_query
    /var/www/html/application/libraries/MY_Database.php - line 133 - query
    /var/www/html/system/libraries/Database.php - line 1075 - query
    /var/www/html/application/libraries/MY_ORM.php - line 1882 - update
    /var/www/html/application/libraries/MY_ORM.php - line 1025 - createAttributes
    /var/www/html/application/libraries/MY_ORM.php - line 729 - inner_submit
    /var/www/html/modules/indicia_svc_import/controllers/services/import.php - line 933 - submit

The error occurs in MYORM::createAttributes when deleting old multi-value attributes. The `fk` prefix, which is present because it is a termlist attribute, needs stripping off to get the attribute_id