Skip to content

fix: prevent in-place dictionary mutation in rerank method #814#818

Open
suhaniiz wants to merge 1 commit into
param20h:devfrom
suhaniiz:bug-fix-mutation-814
Open

fix: prevent in-place dictionary mutation in rerank method #814#818
suhaniiz wants to merge 1 commit into
param20h:devfrom
suhaniiz:bug-fix-mutation-814

Conversation

@suhaniiz

@suhaniiz suhaniiz commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

📋 PR Checklist

Thank you for contributing to PDF-Assistant-RAG! 🎉
Please fill out this template before submitting. PRs without it filled in will be closed.


🔗 Related Issue

Closes #814


📝 What does this PR do?

This PR resolves an in-place dictionary mutation bug in Reranker.rerank() (app/reranker.py):

  • It replaces the direct scoring assignment on referenced objects with a safe shallow copying mechanism (doc.copy()).
  • This guarantees that attaching the "rerank_score" key will not alter the caller's original input dataset or introduce unintended side effects across concurrent data processing workflows.

🗂️ Type of Change

  • 🐛 Bug fix
  • ✨ New feature
  • 🔧 Refactor / code cleanup
  • 📝 Documentation update
  • 🎨 UI / styling change
  • ⚙️ CI / tooling / config change
  • 🧪 Tests

🧪 How was this tested?

  • Tested the affected API endpoints manually
  • Ran the backend locally (uvicorn app.main:app --reload)
  • Ran the frontend locally (npm run dev inside frontend/)
  • Added / updated tests

📸 Screenshots (if UI change)


⚠️ Anything to flag for reviewers?

The change relies on Python's built-in dictionary copying mechanics (.copy()), which safely shields the top-level keys from being injected back into the source document dictionaries. It has no negative impact on memory allocations for standard text payloads.


✅ Self-Review Checklist

  • My branch is based on dev, not main
  • I have not added any secrets / API keys
  • I have not modified main branch or any HuggingFace deployment config
  • My code follows the existing style (no unnecessary formatting changes)
  • I have updated relevant docs / comments if needed

@suhaniiz suhaniiz requested a review from param20h as a code owner July 8, 2026 15:47
@vercel

vercel Bot commented Jul 8, 2026

Copy link
Copy Markdown

@suhaniiz is attempting to deploy a commit to the param20h'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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] Reranker.rerank() modifies input document dictionaries in-place

1 participant