From 1b1f4ce85628764ecdae253d232c33f68396d06b Mon Sep 17 00:00:00 2001 From: wei-kuochen Date: Tue, 25 Feb 2025 16:48:01 +0900 Subject: [PATCH 1/2] weko#50587 fix import issue --- .../weko-search-ui/weko_search_ui/utils.py | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/modules/weko-search-ui/weko_search_ui/utils.py b/modules/weko-search-ui/weko_search_ui/utils.py index 64d0fd164f..1f632d1f93 100644 --- a/modules/weko-search-ui/weko_search_ui/utils.py +++ b/modules/weko-search-ui/weko_search_ui/utils.py @@ -869,10 +869,12 @@ def handle_validate_item_import(list_record, schema) -> list: for record in list_record: errors = record.get("errors") or [] record_id = record.get("id") - if record_id and ( - not represents_int(record_id) or re.search(r"([0-9])", record_id) - ): - errors.append(_("Please specify item ID by half-width number.")) + if record_id: + if not represents_int(record_id) or re.search(r"([0-9])", record_id): + record["id"] = "" + errors.append(_("Please specify item ID by half-width number.")) + else: + record["id"] = int(record_id) if record.get("metadata"): if v2: a = v2.iter_errors(record.get("metadata")) @@ -1742,7 +1744,11 @@ def check(index_id, index_name_path): """ temp_res = [] index_info = None - index_info = Indexes.get_path_list([index_id]) + try: + index_info = Indexes.get_path_list([str(int(index_id))]) + except Exception as ex: + current_app.logger.error(ex) + db.session.rollback() msg_not_exist = _("The specified {} does not exist in system.") if index_info and len(index_info) == 1: @@ -1981,7 +1987,12 @@ def handle_check_doi_indexes(list_record): if doi_ra and publish_status == WEKO_IMPORT_PUBLISH_STATUS[1]: errors.append(_("You cannot keep an item private because it has a DOI.")) # Check restrict DOI with Indexes: - index_ids = [str(idx) for idx in item["metadata"].get("path", [])] + index_ids = [] + try: + index_ids = [str(int(idx)) for idx in item["metadata"].get("path", [])] + except Exception as ex: + current_app.logger.error(ex) + db.session.rollback() if doi_ra and check_restrict_doi_with_indexes(index_ids): if not item.get("status") or item.get("status") == "new": errors.append(err_msg_register_doi) @@ -2931,7 +2942,11 @@ def recursive_sub(keys, node, uri_key, current_type): item_doi_prefix = item_doi item_doi_ra = item.get("doi_ra","") - item_id = item.get('id',"") + item_id = "" + try: + item_id = int(item.get('id')) + except Exception as ex: + current_app.logger.error(ex) checked_registerd_doi_ra = False existed_doi = False From 3ca788a6ffa265c35bed87c0e53c56c964ec4acd Mon Sep 17 00:00:00 2001 From: wei-kuochen Date: Wed, 26 Feb 2025 14:28:01 +0900 Subject: [PATCH 2/2] weko#50587 fix import issue --- modules/weko-search-ui/weko_search_ui/utils.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/weko-search-ui/weko_search_ui/utils.py b/modules/weko-search-ui/weko_search_ui/utils.py index 1f632d1f93..70bac8b8fd 100644 --- a/modules/weko-search-ui/weko_search_ui/utils.py +++ b/modules/weko-search-ui/weko_search_ui/utils.py @@ -874,7 +874,7 @@ def handle_validate_item_import(list_record, schema) -> list: record["id"] = "" errors.append(_("Please specify item ID by half-width number.")) else: - record["id"] = int(record_id) + record["id"] = str(int(record_id)) if record.get("metadata"): if v2: a = v2.iter_errors(record.get("metadata"))