eternnoir / pyTelegramBotAPI

Python Telegram bot api.
GNU General Public License v2.0
8.12k stars 2.03k forks source link

!URGENT - InaccessibleMessage #2130

Closed Badiboy closed 10 months ago

Badiboy commented 10 months ago

@coder2020official

Due to new InaccessibleMessage returned for some cases I got a lot of troubles in project. Before I can access fields like message.from and check if they are filled:

if message.from_user:
   ...

and lot of other fields of message. They were always presented but None if not accessible.

Now all such code raises exceptions, because InaccessibleMessage has no such fields!

For me personally I'll update the project, it's not so critical. BUT. It will bring great backward incompatibility for thousands of users.

I propose to inherit InaccessibleMessage from Message to keep compatibility.

Badiboy commented 10 months ago

Or at least make some stubs returning None with warnings in InaccessibleMessage to prevent such fails.

coder2020official commented 10 months ago

Yes, we didn't think of that.. What are the side effects of inheriting message in inaccessiblemessage? It is a hard decision, because firstly, by inheriting message we will probably introduce more trouble.. secondly, I believe we cannot do anything against API change which breaks everything... So I guess maybe we could return warnings when trying to access non-existent fields in the class..

Badiboy commented 10 months ago

I also do not like that. But the situation is really VERY bad. Once again: not for me, but for users. I know what happend and will care about it).

Wait, i'll think about making some kind of universal stub for any Message field there. I'll let you know.

Badiboy commented 10 months ago

image

Did not found better way, because fields of Message are dynamically constructed and this cannot be automated.

If you confirm - I'll push the update.

Badiboy commented 10 months ago

PS. The idea of developers to add InaccessibleMessage to Bot API is really shitty. 😔

coder2020official commented 10 months ago

why not use getattr?

Badiboy commented 10 months ago

because fields of Message are dynamically constructed and this cannot be automated 👆

Badiboy commented 10 months ago

Or you mean override it?

coder2020official commented 10 months ago

"Called when an attribute lookup has not found the attribute in the usual places (i.e. it is not an instance attribute nor is it found in the class tree for self)." Why not just create getattr function in inaccessiblemessage ?

coder2020official commented 10 months ago

and maybe remove inheriting from message to make it work

Badiboy commented 10 months ago

Why not just create getattr function in inaccessiblemessage ?

I'll check, thanks.

Badiboy commented 10 months ago

and maybe remove inheriting from message to make it work

No inheritance.

Badiboy commented 10 months ago

image

Like this?

coder2020official commented 10 months ago

Yes

Badiboy commented 10 months ago

https://github.com/eternnoir/pyTelegramBotAPI/pull/2131