fix(predict): Guards against undefined tags being returned from search endpoint#24266
fix(predict): Guards against undefined tags being returned from search endpoint#24266
Conversation
…olymarket search endpoint
2956fb7 to
0cbcfd6
Compare
🔍 Smart E2E Test Selection
click to see 🤖 AI reasoning detailsThe changes are in Specific changes:
These are low-risk defensive improvements that don't change core business logic - they just add safety checks to prevent runtime errors when API responses have unexpected shapes. The test file adds corresponding test cases to verify these edge cases are handled correctly. The SmokePredictions tag is the appropriate choice as it covers "Predictions features, prediction market" which directly maps to the Polymarket prediction market provider being modified. |
|




Description
This PR fixes an issue where certain search queries in Predict would return no results despite the API returning valid data.
Reason for change:
When users searched for terms like "nhl", the app would display no results even though the search API returned valid events. Some events had their tags field set to undefined instead of an empty array, causing array method calls to throw. These errors were caught and silently returned an empty array, resulting in "no results" displayed to users.
Solution:
Added defensive checks to safely handle undefined or non-array tags. This ensures malformed events don't crash parsing and valid markets are still displayed. Applied the same pattern to the markets field.
Changelog
CHANGELOG entry: Fixes issue where certain search queries in Predict would return no results
Related issues
Fixes: PRED-414
Manual testing steps
Screenshots/Recordings
Before
After
Pre-merge author checklist
Pre-merge reviewer checklist
Note
Improves resilience of Polymarket market parsing and search results handling.
isSportEventagainst non-arraytags; treat missing tags as emptysortMarkets, treat non-arraymarketsas empty and respectevent.sortByparsePolymarketEvents, default missingtagsto[], ignore inactive markets defensively, and continue parsinggetParsedMarketsFromPolymarketApi, normalize response (events/data) to arrays and, for search (q), return only events with outcomes; remove extraneous loggingmarkets(returns[]) and missingtags(yields empty tags)Written by Cursor Bugbot for commit 0cbcfd6. This will update automatically on new commits. Configure here.