Skip to content

Commit

Permalink
Merge pull request #1776 from dandi/ruff-fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
brianhelba committed Dec 8, 2023
2 parents a1d22a7 + 09e3a38 commit 951b154
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 11 deletions.
2 changes: 1 addition & 1 deletion dandiapi/api/doi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions dandiapi/api/services/metadata/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
8 changes: 4 additions & 4 deletions dandiapi/api/tests/test_dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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.
Expand Down
6 changes: 3 additions & 3 deletions dandiapi/api/views/dandiset.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
)
)
Expand Down
4 changes: 3 additions & 1 deletion scripts/delete_from_versioned_bucket.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import boto3
import click

WARN_THRESHOLD = 1000


def delete_version(bucket, thing):
key = thing['Key']
Expand Down Expand Up @@ -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}?'):
Expand Down

0 comments on commit 951b154

Please sign in to comment.