Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

DateEmptyError raised in _update_loop #3974

Closed
3 tasks done
JaskaranSM opened this issue Nov 13, 2022 · 7 comments
Closed
3 tasks done

DateEmptyError raised in _update_loop #3974

JaskaranSM opened this issue Nov 13, 2022 · 7 comments

Comments

@JaskaranSM
Copy link

Checklist

  • The error is in the library's code, and not in my own.
  • I have searched for this issue before posting it and there isn't a duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.

Code that causes the issue

from telethon.sync import TelegramClient as Client
client = Client(str(config.session_name), config.api_id, config.api_hash)
await client.run_until_disconnected()

Traceback

Traceback (most recent call last):
  File "code.py", line 1, in <code>
userbot  | [E 221113 15:16:30 updates:384] Fatal error handling updates (this is a bug in Telethon, please report it)
userbot  |     Traceback (most recent call last):
userbot  |       File "/usr/local/lib/python3.8/dist-packages/telethon/client/updates.py", line 282, in _update_loop
userbot  |         diff = await self(get_diff)
userbot  |       File "/usr/local/lib/python3.8/dist-packages/telethon/client/users.py", line 30, in __call__
userbot  |         return await self._call(self._sender, request, ordered=ordered)
userbot  |       File "/usr/local/lib/python3.8/dist-packages/telethon/client/users.py", line 84, in _call
userbot  |         result = await future
userbot  |     telethon.errors.rpcerrorlist.DateEmptyError: Date empty (caused by GetDifferenceRequest)

Reporting the bug here as the traceback suggested to do.

@JaskaranSM JaskaranSM changed the title DateEmptyError raised in __update_loop DateEmptyError raised in _update_loop Nov 13, 2022
@Lonami
Copy link
Member

Lonami commented Nov 13, 2022

Can you reliably trigger this error? If the answer is yes and you add a print(self.date) before returning in:

def get_difference(self):
for entry in (ENTRY_ACCOUNT, ENTRY_SECRET):
if entry in self.getting_diff_for:
if entry not in self.map:
raise RuntimeError('Should not try to get difference for an entry without known state')
return fn.updates.GetDifferenceRequest(
pts=self.map[ENTRY_ACCOUNT].pts,
pts_total_limit=None,
date=self.date,
qts=self.map[ENTRY_SECRET].pts if ENTRY_SECRET in self.map else NO_SEQ,
)
return None

What does it show?

@JaskaranSM
Copy link
Author

Can you reliably trigger this error? If the answer is yes and you add a print(self.date) before returning in:

def get_difference(self):
for entry in (ENTRY_ACCOUNT, ENTRY_SECRET):
if entry in self.getting_diff_for:
if entry not in self.map:
raise RuntimeError('Should not try to get difference for an entry without known state')
return fn.updates.GetDifferenceRequest(
pts=self.map[ENTRY_ACCOUNT].pts,
pts_total_limit=None,
date=self.date,
qts=self.map[ENTRY_SECRET].pts if ENTRY_SECRET in self.map else NO_SEQ,
)
return None

What does it show?
added:

def get_difference(self):
        print(f"Getting difference with date={self.date} for={self.getting_diff_for}")

traceback:

Getting difference with date=1970-01-01 00:00:00+00:00 for={<object object at 0x000001A2363C6280>}
[E 221113 10:37:32 updates:384] Fatal error handling updates (this is a bug in Telethon, please report it)
    Traceback (most recent call last):
      File "C:\Users\jaska\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\updates.py", line 282, in _update_loop
        diff = await self(get_diff)
      File "C:\Users\jaska\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 30, in __call__
        return await self._call(self._sender, request, ordered=ordered)
      File "C:\Users\jaska\AppData\Local\Programs\Python\Python310\lib\site-packages\telethon\client\users.py", line 84, in _call
        result = await future
    telethon.errors.rpcerrorlist.DateEmptyError: Date empty (caused by GetDifferenceRequest)

@Lonami
Copy link
Member

Lonami commented Nov 13, 2022

It is strange but the date is indeed 0. It should have been initialized when you logged in but for some reason it was not. If you print((await client(functions.updates.GetStateRequest())).stringify()), is the date the same as above?

@Lonami
Copy link
Member

Lonami commented Nov 13, 2022

The library could pretend there was no gap when attempting to get difference and the date is not known yet. A naive implementation might get in a loop however so perhaps a different fix would be needed. If you login again the error should disappear though (but I'd still like to fix this).

@JaskaranSM
Copy link
Author

JaskaranSM commented Nov 13, 2022

No, its not
State(
pts=46220,
qts=0,
date=datetime.datetime(2022, 11, 13, 17, 44, 54, tzinfo=datetime.timezone.utc),
seq=311,
unread_count=44
)

@Lonami
Copy link
Member

Lonami commented Jan 14, 2023

I cannot reproduce this issue myself. Please install master with:

pip3 install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip

and configure logging with something like this:

import logging
logging.basicConfig(format='[%(levelname) 5s/%(asctime)s] %(name)s: %(message)s', level=logging.WARNING)
logging.getLogger('telethon.messagebox').setLevel(logging.NOTSET + 1)

(You can configure it to your liking, but the messagebox level must be as low as possible. If you have multiple TelegramClient, please set a different base_logger='name' for each in their constructor).

This will print all updates being processed along with the current state of the MessageBox (which deals with the updates).

This log will contain sensitive information, so only share it with people you trust (or redact it before sharing it). You can send it to me privately so that I and nobody else can analyze it (please link to this issue, so I know you're not spam).

With it I'll be able to reproduce the issue reliably locally, pinpoint the problem, and fix it.

@Lonami
Copy link
Member

Lonami commented Apr 29, 2023

Closing due to inactivity.

@Lonami Lonami closed this as completed Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants