fix: always GROUP BY me.id in market_events list query
The LEFT JOIN on instrument_impacts (added for the evaluated subquery) generates N rows per event when the event has N impacts. GROUP BY was only applied when the instrument filter was active — now it's always on. Fixes: total=2 but list shows 6+ duplicates. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -168,8 +168,9 @@ def list_events(
|
||||
sort_col = "me.impact_score"
|
||||
order_sql = f"ORDER BY {sort_col} {'DESC' if sort_dir == 'desc' else 'ASC'}"
|
||||
|
||||
# When joining with instrument_impacts an event can appear multiple times — use GROUP BY
|
||||
group_sql = "GROUP BY me.id" if instrument else ""
|
||||
# Always GROUP BY — the LEFT JOIN on instrument_impacts creates duplicate rows
|
||||
# when an event has multiple impacts (one row per impact without GROUP BY)
|
||||
group_sql = "GROUP BY me.id"
|
||||
|
||||
# Extra columns: evaluated flag + optional instrument score
|
||||
evaluated_col = (
|
||||
|
||||
Reference in New Issue
Block a user