keploy / keploy/ecommerce_sample_app

Unhandled ValueError on quantity param in product_service - Team 177

Open
#5 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
3
Forks
8
Avg merge
3m
Merged PRs (30d)
4

Description

## Description
The `reserve_stock()` and `release_stock()` endpoints both call `int()` directly on user-supplied input without a try/except guard. If the quantity field in the JSON body is a non-integer-castable value (e.g., "abc", null, [], 3.5), Python raises an unhandled ValueError (or TypeError) that Flask converts to a generic 500 Internal Server Error. At that time we need to showcase them as to enter integer or 400 BAD request with the add of int() logic.

## Current Behavior
```
POST /api/v1/products//reserve
Body: { "quantity": "abc" }

→ Python raises: ValueError: invalid literal for int() with base 10: 'abc'
→ Flask returns: 500 Internal Server Error (generic HTML or JSON error page)
The raw traceback is logged server-side, and the client receives no useful error message.
```
in short = if user enter "abc" it showcase 500 status.

## Expected Behavior
The endpoint should validate the input gracefully and return a 400 Bad Request with a clear JSON error message such as:
`{ "error": "quantity must be a positive integer" }`

## Location
app.py

## Impact
• Callers receive an opaque 500 error instead of actionable 400 feedback.
• Every malformed quantity triggers a 500 logged as a server error, polluting error metrics and potentially triggering false alerts.
• The order_service calls /reserve and /release programmatically. If it ever passes a malformed value, it gets a 503/500 cascading failure instead of a clear rejection.

## Suggested Solution
Wrap the int() cast in a try/except, matching the pattern already used in create_product():
add with int(). with some minor logics.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in app.py by locating the reserve_stock() and release_stock() endpoints, then read the existing create_product() validation pattern. Reproduce a request with a non-integer quantity such as "abc", null, [], or 3.5; done means malformed quantities return a clear JSON 400 response instead of an unhandled 500.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.