From 14cf736dd46a0195965951608ce679ee8fa328b0 Mon Sep 17 00:00:00 2001 From: davfsa Date: Sun, 21 Jan 2024 10:36:29 +0100 Subject: [PATCH] `Member.joined_at` can now be None Discord making breaking changes :D --- changes/1812.bugfix.md | 2 ++ hikari/guilds.py | 8 ++++++-- hikari/impl/entity_factory.py | 3 ++- tests/hikari/impl/test_entity_factory.py | 3 ++- 4 files changed, 12 insertions(+), 4 deletions(-) create mode 100644 changes/1812.bugfix.md diff --git a/changes/1812.bugfix.md b/changes/1812.bugfix.md new file mode 100644 index 0000000000..504d10e7e7 --- /dev/null +++ b/changes/1812.bugfix.md @@ -0,0 +1,2 @@ +`Member.joined_at` is now nullable due to breaking API change + - This will be received on guest members with temporary membership diff --git a/hikari/guilds.py b/hikari/guilds.py index 599cab81d3..a521c02867 100644 --- a/hikari/guilds.py +++ b/hikari/guilds.py @@ -359,8 +359,12 @@ class Member(users.User): This will be `hikari.undefined.UNDEFINED` if it's state is unknown. """ - joined_at: datetime.datetime = attrs.field(repr=True) - """The datetime of when this member joined the guild they belong to.""" + joined_at: typing.Optional[datetime.datetime] = attrs.field(repr=True) + """The datetime of when this member joined the guild they belong to. + + This will be `None` for guest members that have been temporarily + invited. + """ nickname: typing.Optional[str] = attrs.field(repr=True) """This member's nickname. diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py index a5f6cebf7f..507bdbb8d8 100644 --- a/hikari/impl/entity_factory.py +++ b/hikari/impl/entity_factory.py @@ -1806,7 +1806,8 @@ def deserialize_member( if guild_id not in role_ids: role_ids.append(guild_id) - joined_at = time.iso8601_datetime_string_to_datetime(payload["joined_at"]) + raw_joined_at = payload["joined_at"] + joined_at = time.iso8601_datetime_string_to_datetime(raw_joined_at) if raw_joined_at is not None else None raw_premium_since = payload.get("premium_since") premium_since = ( diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py index 35d07ed180..6c29210ebb 100644 --- a/tests/hikari/impl/test_entity_factory.py +++ b/tests/hikari/impl/test_entity_factory.py @@ -3230,7 +3230,7 @@ def test_deserialize_member_with_null_fields(self, entity_factory_impl, user_pay { "nick": None, "roles": ["11111", "22222", "33333", "44444"], - "joined_at": "2015-04-26T06:26:56.936000+00:00", + "joined_at": None, "premium_since": None, "deaf": False, "avatar": None, @@ -3244,6 +3244,7 @@ def test_deserialize_member_with_null_fields(self, entity_factory_impl, user_pay assert member.nickname is None assert member.premium_since is None assert member.guild_avatar_hash is None + assert member.joined_at is None assert isinstance(member, guild_models.Member) def test_deserialize_member_with_undefined_fields(self, entity_factory_impl, user_payload):