diff --git a/dandiapi/api/doi.py b/dandiapi/api/doi.py index 9eae5a293..0a549edc4 100644 --- a/dandiapi/api/doi.py +++ b/dandiapi/api/doi.py @@ -65,7 +65,7 @@ def delete_doi(doi: str) -> None: r = s.get(doi_url, headers={'Accept': 'application/vnd.api+json'}) r.raise_for_status() except requests.exceptions.HTTPError as e: - if e.response and e.response.status_code == 404: + if e.response and e.response.status_code == requests.codes.not_found: logging.warning('Tried to get data for nonexistent DOI %s', doi) return logging.exception('Failed to fetch data for DOI %s', doi) diff --git a/dandiapi/api/services/metadata/__init__.py b/dandiapi/api/services/metadata/__init__.py index e7f9b6b20..b6a4c3409 100644 --- a/dandiapi/api/services/metadata/__init__.py +++ b/dandiapi/api/services/metadata/__init__.py @@ -88,13 +88,13 @@ def version_aggregate_assets_summary(version: Version) -> None: .iterator() ) - updated_metadata = {**version.metadata, **{'assetsSummary': assets_summary}} + updated_metadata = {**version.metadata, 'assetsSummary': assets_summary} updated_count = Version.objects.filter(id=version.id, metadata=version.metadata).update( modified=timezone.now(), metadata=updated_metadata ) if updated_count == 0: - logger.info(f'Skipped updating assetsSummary for version {version.id}') + logger.info('Skipped updating assetsSummary for version %s', version.id) def validate_version_metadata(*, version: Version) -> None: diff --git a/dandiapi/api/tests/test_dandiset.py b/dandiapi/api/tests/test_dandiset.py index 9952826c3..b75ba378a 100644 --- a/dandiapi/api/tests/test_dandiset.py +++ b/dandiapi/api/tests/test_dandiset.py @@ -342,11 +342,11 @@ def test_dandiset_rest_create(api_client, user): }, 'most_recent_published_version': None, } - id = int(response.data['identifier']) + dandiset_id = int(response.data['identifier']) # Creating a Dandiset has side affects. # Verify that the user is the only owner. - dandiset = Dandiset.objects.get(id=id) + dandiset = Dandiset.objects.get(id=dandiset_id) assert list(dandiset.owners.all()) == [user] # Verify that a draft Version and VersionMetadata were also created. @@ -632,11 +632,11 @@ def test_dandiset_rest_create_embargoed(api_client, user): }, 'most_recent_published_version': None, } - id = int(response.data['identifier']) + dandiset_id = int(response.data['identifier']) # Creating a Dandiset has side affects. # Verify that the user is the only owner. - dandiset = Dandiset.objects.get(id=id) + dandiset = Dandiset.objects.get(id=dandiset_id) assert list(dandiset.owners.all()) == [user] # Verify that a draft Version and VersionMetadata were also created. diff --git a/dandiapi/api/views/dandiset.py b/dandiapi/api/views/dandiset.py index c035e3572..1a83c7e47 100644 --- a/dandiapi/api/views/dandiset.py +++ b/dandiapi/api/views/dandiset.py @@ -236,9 +236,9 @@ def search(self, request, *args, **kwargs): .filter(dandiset_id__in=[dandiset.id for dandiset in dandisets]) .annotate( **{ - filter_name: Count('asset_id', filter=filter) - for filter_name, filter in query_filters.items() - if filter != Q() + query_filter_name: Count('asset_id', filter=query_filter_q) + for query_filter_name, query_filter_q in query_filters.items() + if query_filter_q != Q() } ) ) diff --git a/scripts/delete_from_versioned_bucket.py b/scripts/delete_from_versioned_bucket.py index 4266d1f14..e6595e80b 100644 --- a/scripts/delete_from_versioned_bucket.py +++ b/scripts/delete_from_versioned_bucket.py @@ -16,6 +16,8 @@ import boto3 import click +WARN_THRESHOLD = 1000 + def delete_version(bucket, thing): key = thing['Key'] @@ -43,7 +45,7 @@ def delete_objects(*, profile: str, bucket: str, prefix: str, force: bool, threa delete_markers = response.get('DeleteMarkers', []) versions = response.get('Versions', []) delete_count = len(delete_markers) + len(versions) - if delete_count >= 1000: + if delete_count >= WARN_THRESHOLD: click.echo('There are more than 1000 objects to delete.') click.echo('This operation will continue to fetch objects until they are all deleted.') if force or click.confirm(f'Delete {delete_count} objects from {bucket.name}/{prefix}?'):