Skip to content

Commit 67c6f61

Browse files
jlhe97claude
andcommitted
Fix empty display_name for Lichess autocomplete results
_slim_profile's "username" field falls back to data.get("id") since autocomplete's raw JSON only has "id", not "username" — but "display_name" never had the same fallback, so it was always "" for every autocomplete candidate. That made the resolver's cheap name-only first pass (_resolve_lichess_by_autocomplete, which ranks all candidates before fetching full profiles for just the top 2) score every candidate against _name_score(name, ""), i.e. effectively unranked/random order rather than name-similarity-driven. Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
1 parent d6f7dec commit 67c6f61

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

lookup/lichess.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,13 @@ def _slim_profile(data: dict) -> dict:
163163
profile = data.get("profile") or {}
164164
return {
165165
"username": data.get("id") or data.get("username", ""),
166-
"display_name": data.get("username", ""),
166+
# Autocomplete's raw JSON only has "id" (lowercase-normalized), not
167+
# "username" — falling back the same way "username" above does
168+
# keeps display_name non-empty for autocomplete-only results
169+
# instead of "", which made _name_score(name, "") score every
170+
# candidate identically (effectively random ranking) in the
171+
# resolver's cheap name-only first pass.
172+
"display_name": data.get("username") or data.get("id", ""),
167173
"title": data.get("title"),
168174
"ratings": {
169175
k: perfs[k]["rating"]

tests/test_lookup.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,14 @@ def test_extracts_username(self):
103103
assert p["username"] == "gmkasparov"
104104
assert p["display_name"] == "GMKasparov"
105105

106+
def test_display_name_falls_back_to_id_for_autocomplete_only_data(self):
107+
# /api/player/autocomplete's raw entries only ever have "id", never
108+
# "username" — display_name must not go empty here, or every
109+
# autocomplete candidate scores identically (effectively unranked)
110+
# in the resolver's cheap name-only first pass.
111+
p = _slim_profile({"id": "kasparov1", "title": None, "perfs": {}})
112+
assert p["display_name"] == "kasparov1"
113+
106114
def test_extracts_title(self):
107115
assert _slim_profile(LICHESS_USER)["title"] == "GM"
108116

0 commit comments

Comments
 (0)