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

KeyError in get_peer_by_username function #64

Open
3 tasks done
troublescope opened this issue Apr 15, 2024 · 0 comments
Open
3 tasks done

KeyError in get_peer_by_username function #64

troublescope opened this issue Apr 15, 2024 · 0 comments

Comments

@troublescope
Copy link
Contributor

Checklist

  • I am sure the error is coming from Pyrofork's code and not elsewhere
  • I have searched in the issue tracker for similar bug reports, including closed ones
  • I ran pip3 install -U git+https://github.com/Mayuri-Chan/pyrofork and reproduced the issue using the latest development version

Description

When attempting to resolve a peer by username, the function get_peer_by_username in the storage.py module is raising a KeyError due to the absence of the key "last_update_on" in the returned result. This issue likely stems from incomplete data or an unexpected format in the database.

Steps to reproduce

  1. Attempt to resolve a peer by username.
  2. Encounter a KeyError due to the absence of "last_update_on" key in the returned result.

Code example

from pyrogram import Client
from typing import Union

async def get_chat() -> None:
    async with Client("my_account") as app:
        try:
            chat: Union[None, dict] = await app.get_chat("pir11")
            if chat:
                print(chat)
            else:
                print("Chat not found.")
        except Exception as e:
            print("An error occurred:", e)

def main() -> None:
    get_chat()

if __name__ == "__main__":
    main()

Logs

Traceback (most recent call last):
  File "<string>", line 1, in tmp
  File "/home/kai/.cache/pypoetry/virtualenvs/caligo-gKLP72oz-py3.9/lib/python3.9/site-packages/pyrogram/methods/users/get_users.py", line 60, in get_users
    user_ids = await asyncio.gather(*[self.resolve_peer(i) for i in user_ids])
  File "/home/kai/.cache/pypoetry/virtualenvs/caligo-gKLP72oz-py3.9/lib/python3.9/site-packages/pyrogram/methods/advanced/resolve_peer.py", line 84, in resolve_peer
    return await self.storage.get_peer_by_username(peer_id)
  File "caligo/core/database/storage.py", line 142, in get_peer_by_username
    if abs(time.time() - res["last_update_on"]) > self.USERNAME_TTL:
KeyError: 'last_update_on'
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

1 participant