Org Web Adapter

hungryroot/jira/be_7381_move_orders_backward_view_returns_500_instead_of_400_on_malformed_post_data.org

ID
82ba470a-4323-4246-8ae3-6332d856edb2

BE-7381 move_orders_backward_view returns 500 instead of 400 on malformed POST data

- source :: https://hungryroot.atlassian.net/browse/BE-7381

- tags :: Hungryroot API Project

- epic :: EP-411 Eng Parking Lot

- sprint :: HR BE Sprint 106 HR BE Sprint 107

- status :: Status - Complete

- priority :: Priority - Low

- points :: 0.25

Tasks

DONE Try running Cursor against bug ticket

workhungryrootbugbe7381ep411sprint106cursor
ID
90cc662e-354b-69f7-d0b6-af6c5c80e80d

Description

Summary

The move_orders_backward_view in app/views/test.py raises an unhandled

ValueError (resulting in a 500 response) when the count POST parameter contains

a non-integer value (e.g. "1 with a stray quote character). This should return a

400 Bad Request instead, since the issue is malformed client input.

Current Behavior

The view does int(request.POST.get("count", 2)) without any validation or error

handling. When a non-integer string is submitted, Python raises:

ValueError: invalid literal for int() with base 10: '"1'

This propagates up as an unhandled 500 Internal Server Error.

Expected Behavior

The view should catch the ValueError and return a 400 Bad Request response with

a descriptive error message indicating the count parameter must be a valid

integer.

Reproduction

POST to the move_orders_backward_view endpoint with count set to a non-integer

value such as "1.

Suggested Fix

Wrap the int() conversion in a try/except block and return a JsonResponse with

status 400 on ValueError.

File

app/views/test.py, line ~405