Skip to content

Commit

Permalink
Don't set obj_ids since it can be missing data
Browse files Browse the repository at this point in the history
(cherry picked from commit praw-dev/praw@1fd5bc2)
  • Loading branch information
LilSpazJoekp committed Nov 28, 2022
1 parent 4b023ff commit 35067ed
Showing 1 changed file with 17 additions and 4 deletions.
21 changes: 17 additions & 4 deletions asyncpraw/objector.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ def _objectify_dict(self, data):
"conversations",
"conversation",
}.intersection(data):
# fetched conversation
data.update(
data.pop("conversation")
if "conversation" in data
Expand All @@ -81,12 +82,24 @@ def _objectify_dict(self, data):
"legacyFirstMessageId",
"state",
}.issubset(data):
# not fetched conversation i.e., from conversations()
del data["objIds"] # delete objIds since it could be missing data
parser = self.parsers["ModmailConversation"]
elif {"conversationIds", "conversations", "messages"}.issubset(data):
data["conversations"] = [
data["conversations"][conversation_id]
for conversation_id in data["conversationIds"]
]
# modmail conversations
conversations = []
for conversation_id in data["conversationIds"]:
conversation = data["conversations"][conversation_id]
# set if the numMessages is same as number of messages in objIds
if conversation["numMessages"] == len(
[obj for obj in conversation["objIds"] if obj["key"] == "messages"]
):
conversation["messages"] = [
self.objectify(data["messages"][obj_id["id"]])
for obj_id in conversation["objIds"]
]
conversations.append(conversation)
data["conversations"] = conversations
data = snake_case_keys(data)
parser = self.parsers["ModmailConversations-list"]
elif {"actionTypeId", "author", "date"}.issubset(data):
Expand Down

0 comments on commit 35067ed

Please sign in to comment.