Skip to content

Use get_object_or_404 where possible#442

Open
brianhelba wants to merge 2 commits intomainfrom
get-or-404
Open

Use get_object_or_404 where possible#442
brianhelba wants to merge 2 commits intomainfrom
get-or-404

Conversation

@brianhelba
Copy link
Member

This simplifies views and moves a lot of code out of overly-broad try blocks.

Please review the docs for get_object_or_404 and get_list_or_404, particularly the ability to use a pre-filtered QuerySet (instead of just a Model class) for the first argument.

@brianhelba brianhelba requested a review from BryonLewis March 18, 2026 14:35
@brianhelba brianhelba changed the title Get or 404 Use get_object_or_404 where possible Mar 18, 2026
Comment on lines +558 to +571
if data.species is not None:
if len(data.species) == 1:
species_id = data.species[0]
return update_nabat_species(
species_id,
data.apiToken,
annotation.nabat_recording.recording_id,
annotation.nabat_recording.survey_event_id,
)
else:
return JsonResponse(
{"error": "NABat only supports one species per recording annotation."},
status=400,
)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What should this function be returning if data.species is None? This looked like a problem before, but it was being masked from the linter by the try block.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant