fix: Replace fragile locals() pattern in PATCH endpoints #11
@ -117,12 +117,20 @@ async def patch_player(
|
|||||||
):
|
):
|
||||||
"""Patch a player (partial update)."""
|
"""Patch a player (partial update)."""
|
||||||
# Build dict of provided fields
|
# Build dict of provided fields
|
||||||
# IMPORTANT: Capture locals() BEFORE creating data dict to avoid including 'data' itself
|
data = {
|
||||||
locals_dict = locals()
|
key: value
|
||||||
data = {}
|
for key, value in {
|
||||||
for key, value in locals_dict.items():
|
'name': name, 'wara': wara, 'image': image, 'image2': image2,
|
||||||
if key not in ('player_id', 'token', 'locals_dict') and value is not None:
|
'team_id': team_id, 'season': season,
|
||||||
data[key] = value
|
'pos_1': pos_1, 'pos_2': pos_2, 'pos_3': pos_3, 'pos_4': pos_4,
|
||||||
|
'pos_5': pos_5, 'pos_6': pos_6, 'pos_7': pos_7, 'pos_8': pos_8,
|
||||||
|
'vanity_card': vanity_card, 'headshot': headshot,
|
||||||
|
'il_return': il_return, 'demotion_week': demotion_week,
|
||||||
|
'strat_code': strat_code, 'bbref_id': bbref_id,
|
||||||
|
'injury_rating': injury_rating, 'sbaref_id': sbaref_id,
|
||||||
|
}.items()
|
||||||
|
if value is not None
|
||||||
|
}
|
||||||
|
|
||||||
return PlayerService.patch_player(player_id, data, token)
|
return PlayerService.patch_player(player_id, data, token)
|
||||||
|
|
||||||
|
|||||||
@ -92,11 +92,17 @@ async def patch_team(
|
|||||||
):
|
):
|
||||||
"""Patch a team (partial update)."""
|
"""Patch a team (partial update)."""
|
||||||
# Build dict of provided fields
|
# Build dict of provided fields
|
||||||
data = {}
|
data = {
|
||||||
locals_dict = locals()
|
key: value
|
||||||
for key, value in locals_dict.items():
|
for key, value in {
|
||||||
if key not in ('team_id', 'token') and value is not None:
|
'manager1_id': manager1_id, 'manager2_id': manager2_id,
|
||||||
data[key] = value
|
'gmid': gmid, 'gmid2': gmid2, 'mascot': mascot,
|
||||||
|
'stadium': stadium, 'thumbnail': thumbnail, 'color': color,
|
||||||
|
'abbrev': abbrev, 'sname': sname, 'lname': lname,
|
||||||
|
'dice_color': dice_color, 'division_id': division_id,
|
||||||
|
}.items()
|
||||||
|
if value is not None
|
||||||
|
}
|
||||||
|
|
||||||
return TeamService.update_team(team_id, data, token)
|
return TeamService.update_team(team_id, data, token)
|
||||||
|
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user