instagrapi icon indicating copy to clipboard operation
instagrapi copied to clipboard

[BUG] Incorrect Datetime Validation

Open AKwoKWH opened this issue 5 months ago • 2 comments

Describe the bug Seem the date time figure was not divided by 1,000,000

To Reproduce

cl = Client()
inbox = cl.direct_threads(amount=50)

Traceback

Unexpected error: 1 validation error for ReplyMessage
visual_media.expiring_media_action_summary.timestamp
  Input should be a valid datetime, dates after 9999 are not supported as unix timestamps [type=datetime_parsing, input_value=1754886851000000, input_type=int]

Expected behavior I don't expect an error here.

Desktop (please complete the following information):

  • OS: [Ubuntu 24.04.2 LTS]
  • Python version [3.12.3]
  • instagrapi version [Version: 2.2.1]

AKwoKWH avatar Nov 06 '25 07:11 AKwoKWH

Found the issue:

class ExpiringMediaActionSummary(TypesBaseModel):
    """Summary of expiring media actions"""
    type: str
    timestamp: datetime
    count: int

Basically it is the "timestamp" in "ExpiringMediaActionSummary" is in the format of 1_000_000 multiplier, so it can pass the pydantic check.

AKwoKWH avatar Nov 10 '25 15:11 AKwoKWH

I don't know the best way to handle it, I do see in the code there are many lines of code like below:

            media["expiring_media_action_summary"]["timestamp"] = datetime.datetime.fromtimestamp(
                int(media["expiring_media_action_summary"]["timestamp"]) // 1_000_000
            )

which converts the timestamp format.

I understand this is not a good practice but my current quick temp solution is a dirty hack that removes the timestamp type in the classs. If anyone have idea on fixing it, please help to do a pull request.

AKwoKWH avatar Nov 10 '25 16:11 AKwoKWH