Skip to content

fix : added monotonic counters for reply_id and answer_id in CommunityManager - #1332

Open
tmdeveloper007 wants to merge 1 commit into
komalharshita:mainfrom
tmdeveloper007:#1328
Open

fix : added monotonic counters for reply_id and answer_id in CommunityManager#1332
tmdeveloper007 wants to merge 1 commit into
komalharshita:mainfrom
tmdeveloper007:#1328

Conversation

@tmdeveloper007

Copy link
Copy Markdown
Contributor

Summary of What Has Been Done

Fixed the reply ID and answer ID generation in src/utils/community.py to use monotonic counters instead of length-based counting, preventing ID collisions after deletions.

Changes Made

  • Added _reply_counters and _answer_counters dicts to CommunityManager.__init__
  • Changed reply_to_discussion to use self._reply_counters for monotonically increasing reply IDs
  • Changed answer_question to use self._answer_counters for monotonically increasing answer IDs

Previously, both methods used len(list) to generate IDs:

"reply_id": f"reply_{len(self.discussions[discussion_id]['replies'])}"
"answer_id": f"answer_{len(self.questions[question_id]['answers'])}"

This caused ID collisions when replies or answers were deleted, as the list length would shorten and subsequent IDs could collide with previously deleted entries.

Impact it Made

  • Ensures reply and answer IDs are unique and monotonically increasing per discussion/question
  • Prevents ID collisions if replies/answers are ever deleted
  • Future-proofs the system for delete functionality

Note

Please assign this PR to the tmdeveloper007 account.

Closes #1329

@vercel

vercel Bot commented Jul 25, 2026

Copy link
Copy Markdown

@tmdeveloper007 is attempting to deploy a commit to the komalsony234-1530's projects Team on Vercel.

A member of the Team first needs to authorize it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

fix : reply_id collision risk after reply deletion in community.py

1 participant