Skip to content

fix: wrap int() conversions in try/except to prevent crashes on bad D…#94

Closed
amansingh1207 wants to merge 1 commit into
Stanzin7:masterfrom
amansingh1207:fix/safe-int-conversion
Closed

fix: wrap int() conversions in try/except to prevent crashes on bad D…#94
amansingh1207 wants to merge 1 commit into
Stanzin7:masterfrom
amansingh1207:fix/safe-int-conversion

Conversation

@amansingh1207

Copy link
Copy Markdown
Contributor

Problem

Two int() conversions in database.py had no error handling:

  • int(row["count"]) at page view query
  • int(row["avg_security_score"] or 0) in stats aggregation

If the database contains a corrupt/non-numeric value, these raise
ValueError/TypeError and crash the API endpoint.

Fix

  • Wrapped int(row["count"]) in try/except returning 0 on failure
  • Added type guard for avg_security_score before conversion

Impact

Prevents unhandled exceptions that could expose internal stack traces
or cause API downtime.

@Stanzin7

Copy link
Copy Markdown
Owner

Thanks @amansingh1207 — both lines this edits still exist (database.py:423 and :711), so it would merge, but the crashes it guards against can't occur on current master: get_statistics is already wrapped in try/except Exception (database.py:681-723) and returns safe defaults. Since it guards a non-reachable failure, I'd recommend closing.

@Stanzin7 Stanzin7 closed this Jun 27, 2026
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.

2 participants