Skip to content

Commit

Permalink
Merge pull request #1808 from dandi/catch-deleted-versions
Browse files Browse the repository at this point in the history
Check if version still exists before proceeding with validation
  • Loading branch information
mvandenburgh authored Jan 4, 2024
2 parents 6b5641f + e98a172 commit e6f979a
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion dandiapi/api/services/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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':
Expand All @@ -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()

Expand Down

0 comments on commit e6f979a

Please sign in to comment.