Skip to content

Commit

Permalink
Update log message in validate_version_metadata
Browse files Browse the repository at this point in the history
Also add test to check that versions validated with a status besides
`PENDING` are skipped
  • Loading branch information
jjnesbitt committed Jul 29, 2024
1 parent a3f2d9d commit 418e39f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion dandiapi/api/services/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ def _get_version_validation_result(
# If the version has since been modified, return early
if current_version.status != Version.Status.PENDING:
logger.info(
'Skipping validation for version %s due to concurrent modification', version_id
'Skipping validation for version with a status of %s', current_version.status
)
return

Expand Down
20 changes: 20 additions & 0 deletions dandiapi/api/tests/test_tasks.py
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,26 @@ def test_validate_version_metadata(draft_version: Version, asset: Asset):
assert draft_version.modified > old_modified


@pytest.mark.django_db()
def test_validate_version_metadata_non_pending_version(draft_version: Version, asset: Asset):
# Bypass .save to manually set an older timestamp, set status to INVALID
old_modified = timezone.now() - datetime.timedelta(minutes=10)
updated = Version.objects.filter(id=draft_version.id).update(
modified=old_modified, status=Version.Status.INVALID, validation_errors=['foobar']
)
assert updated == 1

draft_version.refresh_from_db()
old_validation_errors = draft_version.validation_errors
tasks.validate_version_metadata_task(draft_version.id)
draft_version.refresh_from_db()

# Assert fields not updated
assert draft_version.status == Version.Status.INVALID
assert draft_version.validation_errors == old_validation_errors
assert draft_version.modified == old_modified


@pytest.mark.django_db()
def test_validate_version_metadata_no_side_effects(draft_version: Version, asset: Asset):
draft_version.assets.add(asset)
Expand Down

0 comments on commit 418e39f

Please sign in to comment.