Skip to content

Commit

Permalink
Fix deserializing old forum channels on GUILD_CREATE missing some f…
Browse files Browse the repository at this point in the history
…ields (#1439)
  • Loading branch information
davfsa authored Jan 2, 2023
1 parent b09d7f5 commit a406cd4
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions changes/1439.bugfix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fix deserializing old forum channels on `GUILD_CREATE` missing some fields.
5 changes: 3 additions & 2 deletions hikari/impl/entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -1191,9 +1191,10 @@ def deserialize_guild_forum_channel(
position=int(payload["position"]),
available_tags=available_tags,
flags=channel_models.ChannelFlag(payload["flags"]),
default_layout=channel_models.ForumLayoutType(payload["default_forum_layout"]),
# Discord may send None here for old channels, but they are just NOT_SET
default_layout=channel_models.ForumLayoutType(payload.get("default_forum_layout", 0)),
# Discord may send None here for old channels, but they are just LATEST_ACTIVITY
default_sort_order=channel_models.ForumSortOrderType(payload["default_sort_order"] or 0),
default_sort_order=channel_models.ForumSortOrderType(payload.get("default_sort_order") or 0),
default_reaction_emoji_id=reaction_emoji_id,
default_reaction_emoji_name=reaction_emoji_name,
)
Expand Down
4 changes: 4 additions & 0 deletions tests/hikari/impl/test_entity_factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -2074,6 +2074,8 @@ def test_deserialize_guild_forum_channel_with_unset_fields(self, entity_factory_
del guild_forum_channel_payload["default_auto_archive_duration"]
del guild_forum_channel_payload["default_thread_rate_limit_per_user"]
del guild_forum_channel_payload["rate_limit_per_user"]
del guild_forum_channel_payload["default_sort_order"]
del guild_forum_channel_payload["default_forum_layout"]

forum_channel = entity_factory_impl.deserialize_guild_forum_channel(guild_forum_channel_payload)

Expand All @@ -2085,6 +2087,8 @@ def test_deserialize_guild_forum_channel_with_unset_fields(self, entity_factory_
assert forum_channel.default_auto_archive_duration == datetime.timedelta(minutes=1440)
assert forum_channel.default_thread_rate_limit_per_user == datetime.timedelta(minutes=0)
assert forum_channel.rate_limit_per_user == datetime.timedelta(minutes=0)
assert forum_channel.default_sort_order == channel_models.ForumSortOrderType.LATEST_ACTIVITY
assert forum_channel.default_layout == channel_models.ForumLayoutType.NOT_SET

def test_serialize_forum_tag(self, entity_factory_impl):
tag = channel_models.ForumTag(id=snowflakes.Snowflake(123), name="test", moderated=True, emoji=None)
Expand Down

0 comments on commit a406cd4

Please sign in to comment.