From e98a172bce9926421f665072366add6c90933f36 Mon Sep 17 00:00:00 2001 From: Mike VanDenburgh Date: Thu, 4 Jan 2024 12:01:37 -0500 Subject: [PATCH] Check if version has been deleted before continuing with validation --- dandiapi/api/services/metadata/__init__.py | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/dandiapi/api/services/metadata/__init__.py b/dandiapi/api/services/metadata/__init__.py index b6a4c3409..7df4d8fd4 100644 --- a/dandiapi/api/services/metadata/__init__.py +++ b/dandiapi/api/services/metadata/__init__.py @@ -120,7 +120,9 @@ def _build_validatable_version_metadata(version: Version) -> dict: } return metadata_for_validation - logger.info('Validating dandiset metadata for version %s', version.id) + version_id = version.id + + logger.info('Validating dandiset metadata for version %s', version_id) # Published versions are immutable if version.version != 'draft': @@ -134,6 +136,13 @@ def _build_validatable_version_metadata(version: Version) -> dict: .select_for_update() .first() ) + + # It's possible for this version to get deleted during execution of this function. + # If that happens *before* the select_for_update query, return early. + if version is None: + logger.info('Version %s no longer exists, skipping validation', version_id) + return + version.status = Version.Status.VALIDATING version.save()