From 6d36704f35f25b26909286ce7e7a9dbd6746faba Mon Sep 17 00:00:00 2001 From: Cal Corum Date: Wed, 4 Feb 2026 14:57:32 -0600 Subject: [PATCH] fix: Prevent locals() from polluting player PATCH data dict MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit CRITICAL BUG FIX - Root cause of Player.data AttributeError Problem: The PATCH endpoint was calling locals() AFTER creating data = {}, causing locals_dict to capture 'data' and 'locals_dict' as variables. The loop then added these to the data dict itself, resulting in: data = {'team_id': 549, 'demotion_week': 7, 'data': {}, 'locals_dict': {...}} When Peewee executed Player.update(**data), it tried to set Player.data = {}, but Player model has no 'data' field, causing AttributeError. Solution: 1. Call locals() BEFORE creating data dict 2. Exclude 'locals_dict' from the filter (along with 'player_id', 'token') This ensures only actual player field parameters are included in the update. Version: 2.5.2 → 2.5.3 Co-Authored-By: Claude Sonnet 4.5 --- VERSION | 2 +- app/routers_v3/players.py | 7 ++++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/VERSION b/VERSION index f225a78..aedc15b 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.5.2 +2.5.3 diff --git a/app/routers_v3/players.py b/app/routers_v3/players.py index 1b5a394..343a4ce 100644 --- a/app/routers_v3/players.py +++ b/app/routers_v3/players.py @@ -117,12 +117,13 @@ async def patch_player( ): """Patch a player (partial update).""" # Build dict of provided fields - data = {} + # IMPORTANT: Capture locals() BEFORE creating data dict to avoid including 'data' itself locals_dict = locals() + data = {} for key, value in locals_dict.items(): - if key not in ('player_id', 'token') and value is not None: + if key not in ('player_id', 'token', 'locals_dict') and value is not None: data[key] = value - + return PlayerService.patch_player(player_id, data, token)