Repository: hikari-py/hikari
Pull request #1439 (2023-01-02 11:18:39)

Fix deserializing old forum channels on `GUILD_CREATE` missing some fields
### Checklist
<!-- Make sure to tick all the following boxes by putting an `x` in between (like this `[x]`) -->
- [x] I have run `nox` and all the pipelines have passed.
- [x] I have made unittests according to the code I have added/modified/deleted.



Patch:
diff --git a/changes/1439.bugfix.md b/changes/1439.bugfix.md
new file mode 100644
index 00000000..f8cbd644
--- /dev/null
+++ b/changes/1439.bugfix.md
@@ -0,0 +1,1 @@
+Fix deserializing old forum channels on `GUILD_CREATE` missing some fields.
diff --git a/hikari/impl/entity_factory.py b/hikari/impl/entity_factory.py
index 9c8b242e..a2fa7f0a 100644
--- a/hikari/impl/entity_factory.py
+++ b/hikari/impl/entity_factory.py
@@ -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,
         )


Test patch:
diff --git a/tests/hikari/impl/test_entity_factory.py b/tests/hikari/impl/test_entity_factory.py
index 05064188..8b17f433 100644
--- a/tests/hikari/impl/test_entity_factory.py
+++ b/tests/hikari/impl/test_entity_factory.py
@@ -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)
 
@@ -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)