Skip to content

fix: enforce string sorting key to handle mixed metadata types (#797)#801

Open
suhaniiz wants to merge 1 commit into
param20h:devfrom
suhaniiz:fix/json-sort-type-crash-797
Open

fix: enforce string sorting key to handle mixed metadata types (#797)#801
suhaniiz wants to merge 1 commit into
param20h:devfrom
suhaniiz:fix/json-sort-type-crash-797

Conversation

@suhaniiz

@suhaniiz suhaniiz commented Jul 6, 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 #797


📝 What does this PR do?

Fixes a potential TypeError crash within the graph serialization sanitization pipeline (_convert_sets_for_json).

When processing diverse document chunks, metadata keys like page or chunk_index can occasionally emerge with mixed primitive types (e.g., an integer page identifier 14 alongside an explicit textual page boundary descriptor "appendix_b"). When elements containing these variant types are collected into graph node/edge sets, calling Python's native sorted() without a fallback comparator explicitly throws an unhandled error ('<' not supported between instances of 'str' and 'int').

This PR introduces a uniform string representation key fallback (key=str) within the sorting comprehensions, ensuring string-based sorting ordering evaluations complete predictably across heterogenous document indices without interruption.


🗂️ 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
  • Verified through manual verification that passing collections containing mixed integers and string literals sorts smoothly without comparison errors.

📸 Screenshots (if UI change)

N/A (Backend logic fix)


⚠️ Anything to flag for reviewers?

The sorting uses key=str lazily inside the generator wrapper expressions. This gracefully yields an alphanumeric sort without throwing comparison evaluation errors, maintaining stability regardless of arbitrary source document structural discrepancies.


✅ 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 6, 2026 18:38
@vercel

vercel Bot commented Jul 6, 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] : Potential Type Crash in JSON Sanitization Sorting

1 participant