instagrapi
instagrapi copied to clipboard
[BUG] Pydantic fails to parse microseconds as datetime, fix by dividing by a million.
Try Instagrapi SaaS with a free trial https://hikerapi.com/p/5GBWznd3
Describe the bug Any usage of a type that has 'datetime' in it may fail (e.g. in types.py: Media, Comment, Story, ReplyMessage, DirectMessage, DirectThread, Highlight, Note).
To Reproduce Call cl.direct_threads or cl.direct_send etc.
Expected behavior No error appears when calling any function that receives a datetime object from instagram.
Desktop (please complete the following information):
- OS: Windows 11 Home edition
- Python version: 3.10.4
- instagrapi version: 2.0.1
Additional context Many of the current open issues that are bugs are simply because of this. Some solutions have been suggested. The simplest solution I found was to divide any incoming datetime by 1_000_000. Some check on how large it is should probably happen to make sure this is indeed time in microseconds.
Creating a Model class that inherits from BaseModel but fixes this issue, and letting everything inherit from there might be a clean solution, alternatively, call a function that fixes any datetime in incoming data in all relevant functions in extractors.py. IDK which is better.
Seems to be a duplicate of #1712, which already got fixed, apparently.