Open M4rtinK opened 7 years ago
For storage and caching, I'd use the twitter.Status()._json
attribute since that is straight from twitter. I'll look into this, but I don't think it will ever be a true one to one from dict -> dict since there are going to be things like empty lists (hashtags
etc.) that don't get set on the NewFromJson
method that are present (even if they're empty) on the original AsDict
(if that makes sense).
I'm also seeing no media being populated in the Status
. 3 years after this was opened, is there a way forward?
I've recently implemented tweet caching in my Twitter app, based on the
AsDict()
for serialization &NewFromJsonDict()
for deserialization.But I've noticed an inconsistency - if the serialized tweet has media, the media description is correctly serialized to the dict by
AsDict()
, but when the tweet is deserialized withNewFromJsonDict()
themedia
property of the new Status instance is None.I've also tried passing the dict to the Status constructor instead of kwargs, but the media is not None, but instead contains a list of dicts describing the media, not the expected list Media instances.
This is a short reproducer demonstrating the issue:
Looking at the serialization/deserialization code in
models.py
it seems the issue is caused by the serialization code putting the dicts representing the media instances to key calledmedia
but then inNewFromJsonDict()
it's looking for media in a dict in the "entities" or "extended_entities" key, not in the toplevel dict namespace:So these possible solutions come to me mind:
AsDict()
should place the list of media dicts to ["entities"]["media"] or ["extended_entitites"]["media"] instead to the toplevel "media" keyNewFromJson()
should look for media also in the top-level "media" key