From 3f90f4144d1985eeba9b20e984a7411e26d2cdaa Mon Sep 17 00:00:00 2001 From: Claude Date: Fri, 30 Oct 2026 15:48:43 +0000 Subject: [PATCH] Keep null user display name as None Co-Authored-By: Claude Opus 5.5 Claude-Session: https://claude.ai/code/session_01SLHDn51P7snTSyxtuDToEb --- src/spotifyaio/models.py | 2 +- tests/test_spotify.py | 16 ++++++++++++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/src/spotifyaio/models.py b/src/spotifyaio/models.py index 2cdfef54..ac1a784c 100644 --- a/src/spotifyaio/models.py +++ b/src/spotifyaio/models.py @@ -545,7 +545,7 @@ class ProductType(StrEnum): class BaseUserProfile(DataClassORJSONMixin): """Base user profile model.""" - display_name: str + display_name: str | None user_id: str = field(metadata=field_options(alias="id")) images: list[Image] object_type: str = field(metadata=field_options(alias="type")) diff --git a/tests/test_spotify.py b/tests/test_spotify.py index e366333b..1c42b856 100644 --- a/tests/test_spotify.py +++ b/tests/test_spotify.py @@ -832,6 +832,22 @@ async def test_get_current_user( ) +async def test_get_current_user_without_display_name( + responses: aiointercept, + authenticated_client: SpotifyClient, +) -> None: + """Test retrieving current user without a display name.""" + body = json.loads(load_fixture("current_user.json")) + body["display_name"] = None + responses.get( + f"{SPOTIFY_URL}/v1/me", + status=200, + body=json.dumps(body), + ) + response = await authenticated_client.get_current_user() + assert response.display_name is None + + async def test_get_current_user_without_deprecated_fields( responses: aiointercept, authenticated_client: SpotifyClient,