Skip to content

Commit

Permalink
Add "_type" to *all* telethon.tl.types objects in ndjson
Browse files Browse the repository at this point in the history
Previously SearchTelegram.serialize_obj would only add the "_type" tag to the JSON object representing a TLObject if that object was an immediate child property of another TLObject - other cases would not add the _type, in particular

- where a TLObject has a property whose value is a *list* of other TLObjects, the members of the list would not have a _type in the JSON - this is most noticeable for things like Message.entities, Page.blocks, etc.
- the initial object passed in to serialize_obj did not have a _type added
  • Loading branch information
ianroberts committed Aug 22, 2023
1 parent 2e69c67 commit 948d0d3
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions datasources/telegram/search_telegram.py
Original file line number Diff line number Diff line change
Expand Up @@ -675,8 +675,6 @@ def serialize_obj(input_obj):
mapped_obj[item] = value.timestamp()
elif type(value).__module__ in ("telethon.tl.types", "telethon.tl.custom.forward"):
mapped_obj[item] = SearchTelegram.serialize_obj(value)
if type(obj[item]) is not dict:
mapped_obj[item]["_type"] = type(value).__name__
elif type(value) is list:
mapped_obj[item] = [SearchTelegram.serialize_obj(item) for item in value]
elif type(value).__module__[0:8] == "telethon":
Expand All @@ -693,6 +691,9 @@ def serialize_obj(input_obj):
else:
mapped_obj[item] = value

# Add the _type if the original object was a telethon type
if type(input_obj).__module__ in ("telethon.tl.types", "telethon.tl.custom.forward"):
mapped_obj["_type"] = type(input_obj).__name__
return mapped_obj

@staticmethod
Expand Down

0 comments on commit 948d0d3

Please sign in to comment.