Skip to content

fix: guard against ZeroDivisionError when response.count is 0 in TwitterCountPenalty#334

Open
Grizouforever wants to merge 1 commit intoDesearch-ai:mainfrom
Grizouforever:fix/zerodivision-twitter-count-penalty
Open

fix: guard against ZeroDivisionError when response.count is 0 in TwitterCountPenalty#334
Grizouforever wants to merge 1 commit intoDesearch-ai:mainfrom
Grizouforever:fix/zerodivision-twitter-count-penalty

Conversation

@Grizouforever
Copy link
Copy Markdown

Summary

  • TwitterCountPenalty.calculate in neurons/validators/penalty/twitter_count_penalty.py computed 1 - results_count / response.count without checking for response.count == 0, causing ZeroDivisionError.
  • Fix: add an early-continue guard that sets penalties[index] = 0.0 and skips to the next response when response.count == 0.

Test plan

  • Pass a TwitterSearchSynapse with count=0 — should return penalty 0.0 without raising
  • Normal responses still compute the correct penalty ratio
  • Syntax validated: python3 -c "import ast; ast.parse(open('neurons/validators/penalty/twitter_count_penalty.py').read())"

Closes #333

TwitterCountPenalty computed `1 - results_count / response.count`
without checking whether response.count is zero first, causing a
ZeroDivisionError at runtime. Add an early-continue guard that sets
the penalty to 0.0 and skips to the next response when response.count
equals zero.
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.

fix: ZeroDivisionError in TwitterCountPenalty when response.count is 0

1 participant