Skip to content

Commit

Permalink
Merge pull request #87 from hubmapconsortium/kburke/uuidSchemaRevisions
Browse files Browse the repository at this point in the history
Fix read endpoint to return results for identifiers without ancestors.
  • Loading branch information
yuanzhou authored May 31, 2022
2 parents 12fc5f2 + 56814d2 commit a0e966a
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/uuid_worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.")
Expand All @@ -858,8 +858,11 @@ 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 '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
if results is None or not results:
Expand Down

0 comments on commit a0e966a

Please sign in to comment.