fix: validate thing_id before GCS upload to prevent orphaned blobs#698
Merged
Conversation
Move session.get(Thing, thing_id) ahead of gcs_upload in upload_and_record_asset so requests with a nonexistent thing_id short-circuit with 409 before any GCS object is written. Previously the file was uploaded first, then the 409 raised, leaving an orphaned blob with no Asset row. Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes POST /asset/upload-and-record to validate thing_id (i.e., confirm the Thing exists) before uploading the file to GCS, preventing orphaned GCS objects when the request ultimately fails with a 409.
Changes:
- Reordered
upload_and_record_assetto look upThingbefore callinggcs_upload. - Updated the numbered section comments to reflect the new execution order.
This was referenced Jun 8, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
POST /asset/upload-and-recorduploaded the file to GCS before callingsession.get(Thing, thing_id). Whenthing_idwas invalid, the endpoint then raised 409 and returned — leaving an orphaned object in GCS with noAssetrow pointing at it.thing_id.How
Thinglookup ahead ofgcs_uploadin api/asset.py:242.Notes
test_upload_and_record_asset_bad_thing_id(tests/test_asset.py:452) still asserts the same 409 contract.gcs_uploadto confirm it isn't called; current test suite doesn't reach actual GCS in CI.