Skip to content

Return 400 for an invalid timestamp in /api/upload before saving the image - #256

Merged
pradeeban merged 1 commit into
KathiraveluLab:mainfrom
madhavzanwar:fix/upload-invalid-timestamp
Oct 18, 2026
Merged

pradeeban merged 1 commit into
KathiraveluLab:mainfrom
madhavzanwar:fix/upload-invalid-timestamp

Conversation

@madhavzanwar

Copy link
Copy Markdown
Contributor

Fixes #254

POST /api/upload accepted any timestamp string. An invalid value such as yesterday only failed later in DreamsPipeline.process_new_post (datetime.fromisoformat). That produced a 500 and left the already-saved image in the upload folder.

Change
In dreams_app/app/ingestion/routes.py, the timestamp is now checked with datetime.fromisoformat right after the required-field check. An invalid value returns 400 {"error": "Invalid timestamp, expected ISO 8601"} before anything is written. The new test tests/test_upload_timestamp.py posts an invalid timestamp and checks for a 400, an empty upload folder, and that the pipeline was never called.

The check uses the same parser as the pipeline, so accepted formats don't change. Timestamps with or without an offset, and the default (now), still pass validation.

Testing

  • The new test failed before the change (the route accepted the value and ran the pipeline) and passes now.
  • Before the change I reproduced the 500 and the leftover file by posting to the route with the real pipeline class.
  • Full suite: 350 passed, 1 skipped. I excluded tests/test_places365_classifier.py, which needs torchvision, in my environment.

AI assistance was used for this change; the tests were run before submitting.

An unparseable timestamp raised ValueError inside the pipeline, which returned
a 500 and left the already-saved image in the upload folder. Validate it right
after the required-field check and return 400, and add a test.
Copilot AI balanced review requested due to automatic review settings October 17, 2026 22:21

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

An organization owner can choose the repository organization as the billing source for reviews requested by members with a paid Copilot license. Learn about Copilot code review billing.

@pradeeban
pradeeban merged commit d3f23ea into KathiraveluLab:main Oct 18, 2026
1 of 3 checks passed
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.

/api/upload returns a 500 and leaves the image on disk when timestamp is not ISO 8601

3 participants