fix: weapon_type filter uses subquery instead of rd table reference

The rd table is only available inside the CTE, not in the outer WHERE.
Use EXISTS subquery against item_raw_data for skill-based weapon type
filtering (same pattern as spell_contains fix).

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
Erik 2026-04-08 17:43:13 +02:00
parent 9749eafde4
commit 7f7595b5b6

View file

@ -3245,15 +3245,11 @@ async def search_items(
# Weapons: ObjectClass 1 (MeleeWeapon), 9 (MissileWeapon), 31 (WandStaffOrb)
if weapon_type:
wt = weapon_type.lower()
# Skill-based: Heavy=44, Light=45, Finesse=46, TwoHanded=41
if wt == 'heavy':
conditions.append("(object_class = 1 AND (rd.int_values->>'218103840')::int = 44)")
elif wt == 'light':
conditions.append("(object_class = 1 AND (rd.int_values->>'218103840')::int = 45)")
elif wt == 'finesse':
conditions.append("(object_class = 1 AND (rd.int_values->>'218103840')::int = 46)")
elif wt == 'two_handed':
conditions.append("(object_class = 1 AND (rd.int_values->>'218103840')::int = 41)")
# Skill-based: use subquery against item_raw_data (rd not available in outer query)
# Heavy=44, Light=45, Finesse=46, TwoHanded=41
skill_map = {'heavy': 44, 'light': 45, 'finesse': 46, 'two_handed': 41}
if wt in skill_map:
conditions.append(f"(object_class = 1 AND EXISTS (SELECT 1 FROM item_raw_data wrd WHERE wrd.item_id = db_item_id AND (wrd.int_values->>'218103840')::int = {skill_map[wt]}))")
# Name-based missile sub-types
elif wt == 'bow':
conditions.append("(object_class = 9 AND name ILIKE '%bow%' AND name NOT ILIKE '%crossbow%')")