From 082af1f4674b811185ebfc504b6989b327fd38ce Mon Sep 17 00:00:00 2001 From: Karl Burke Date: Thu, 26 May 2022 16:30:38 -0400 Subject: [PATCH 1/2] Fix read endpoint to return results for identifiers without ancestors. https://github.com/hubmapconsortium/uuid-api/issues/86 --- src/uuid_worker.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/uuid_worker.py b/src/uuid_worker.py index 91a4c1d..c89c5ca 100644 --- a/src/uuid_worker.py +++ b/src/uuid_worker.py @@ -122,7 +122,7 @@ class DataIdType(Enum): " ,uuids.USER_EMAIL AS email" " ,GROUP_CONCAT(ancestors.ancestor_uuid) AS ancestor_ids" " FROM uuids" - " INNER JOIN ancestors ON uuids.UUID = ancestors.DESCENDANT_UUID" + " LEFT OUTER JOIN ancestors ON uuids.UUID = ancestors.DESCENDANT_UUID" " LEFT OUTER JOIN uuids_attributes ON uuids.UUID = uuids_attributes.UUID" " WHERE uuids.UUID = %s" ) @@ -849,7 +849,7 @@ def getIdInfo(self, app_id): curs.execute(SQL_SELECT_ID_INFO_BY_UUID , tid) else: - self.logger.error("Unable to retrief identfier infomation when data_id_type=", data_id_type, " app_id=", app_id, ".") + self.logger.error("Unable to retrieve identfier information when data_id_type=", data_id_type, " app_id=", app_id, ".") pass except BaseException as err: self.logger.error("Unexpected database problem. err=",err,". Verify schema is current model.") @@ -860,6 +860,8 @@ def getIdInfo(self, app_id): for item in results: if item['submission_id'] == None: item.pop('submission_id') + if item['ancestor_ids'] == None: + item.pop('ancestor_ids') # In Python, empty sequences (strings, lists, tuples) are false if results is None or not results: From 56814d278878b4318c8b702d8d65ed2eaaa93695 Mon Sep 17 00:00:00 2001 From: Karl Burke Date: Tue, 31 May 2022 11:49:24 -0400 Subject: [PATCH 2/2] Verify dictionary entries present and that the ancestor_ids has no entries before removing. --- src/uuid_worker.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/uuid_worker.py b/src/uuid_worker.py index c89c5ca..aaef210 100644 --- a/src/uuid_worker.py +++ b/src/uuid_worker.py @@ -658,7 +658,7 @@ def newUUIDs(self, parentIDs, entityType, userId, userEmail, nIds, organ_code=No try: with closing(dbConn.cursor()) as curs: - # Count on DBAPI-compliant MySQL Connetor/Python to begin a transaction on the first + # Count on DBAPI-compliant MySQL Connector/Python to begin a transaction on the first # SQL statement and keep open until explicit commit() call to allow rollback(), so # uuid and uuid_attributes committed atomically. curs.executemany(SQL_INSERT_UUIDS @@ -858,9 +858,10 @@ def getIdInfo(self, app_id): curs.fetchall()] # remove the submission_id column if it is null for item in results: - if item['submission_id'] == None: + item['ancestor_ids'] = [] + if 'submission_id' in item and item['submission_id'] == None: item.pop('submission_id') - if item['ancestor_ids'] == None: + if 'ancestor_ids' in item and (item['ancestor_ids'] == None or len(item['ancestor_ids']) == 0): item.pop('ancestor_ids') # In Python, empty sequences (strings, lists, tuples) are false