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

Cannot edit caption of File uploaded by other User in Channel #4193

Closed
3 tasks done
NotStatilko opened this issue Sep 7, 2023 · 2 comments
Closed
3 tasks done

Cannot edit caption of File uploaded by other User in Channel #4193

NotStatilko opened this issue Sep 7, 2023 · 2 comments

Comments

@NotStatilko
Copy link
Contributor

Code that causes the issue

  1. Make a Channel (C) from user A
  2. Add user B to C & grant all Admin privileges
  3. Upload any Document to C from B
  4. Run code example below from user A
from telethon.sync import TelegramClient
from telethon.types import PeerChannel

API_ID = ...
API_HASH = ...
CHANNEL = PeerChannel(...)

client = TelegramClient(...)
client.start()

channel = client.get_entity(CHANNEL)

message = next(client.iter_messages(channel))
print(message.edit('Test caption') is None)
# ^ Message is NOT edited if result is True

Expected behavior

I believe that user A (with Owner privileges) should change caption of Message of user B.

Actual behavior

Document message is NOT edited (None returned).

Traceback

No Traceback.

Telethon version

1.29.3 (HEAD)

Python version

3.9.2

Operating system (including distribution name and version)

Debian 11

Other details

This can be easily done within Telegram. Moreover, if B edit caption of file uploaded by himself, then things is OK (Document caption is edited).

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 an open duplicate.
  • I ran pip install -U https://github.com/LonamiWebs/Telethon/archive/v1.zip and triggered the bug in the latest version.
@NotStatilko
Copy link
Contributor Author

NotStatilko commented Sep 7, 2023

Little debug show me that probably the problem in this two lines of code:

        if self.fwd_from or not self.out or not self._client:
            return None  # We assume self.out was patched for our chat

As far i understand, self.out stands for "We are sender of this Message or not?". What is a reason behind using this in such statement? What if we just remove the or not self.out? This will resolve the problem described in this issue.

UPD: It seems that client.edit_message works fine on this Issue.

NotStatilko added a commit to NonProjects/tgbox that referenced this issue Sep 7, 2023
It seems that there is a bug in Telethon library
that restrict us to change a caption of Documents
uploaded by other users even if we have rights
for this action. This can be fixed by using
less abstract method on TelegramClient.

See github.com/LonamiWebs/Telethon/issues/4193
NotStatilko added a commit to NonProjects/tgbox that referenced this issue Sep 7, 2023
It seems that there is a bug in Telethon library
that restrict us to change a caption of Documents
uploaded by other users even if we have rights
for this action. This can be fixed by using
less abstract method on TelegramClient.

See github.com/LonamiWebs/Telethon/issues/4193
@Lonami
Copy link
Member

Lonami commented Sep 7, 2023

Thanks for the very detailed report. To be fair, it's probably safe to remove that check entirely.

Trying to emulate server rules locally does not often end well.

@Lonami Lonami closed this as completed Sep 7, 2023
@Lonami Lonami reopened this Sep 7, 2023
NotStatilko added a commit to NotStatilko/Telethon that referenced this issue Sep 8, 2023
@Lonami Lonami closed this as completed in 72faa89 Sep 8, 2023
vanutp pushed a commit to vanutp/Telethon that referenced this issue Sep 28, 2023
New-dev0 added a commit to TeamUltroid/Telethon that referenced this issue Dec 11, 2023
* Change bug report template to an issue form

Lifted from Tachiyomi and adapted for Telethon.

See: https://github.com/tachiyomiorg/tachiyomi/blob/master/.github/ISSUE_TEMPLATE/report_issue.yml

* Change feature request template to an issue form

* Add dedicated form for documentation issues

* Update some fields in the GH issue template

* Fix comment_to for a group of messages (LonamiWebs#4120)

* Clarify OS field in bug report template

* Handle CancelledError inside mtprotosender recv loop

* Add missing formatting arg in logging call

Noticed in LonamiWebs#4123.

* Document more RPC errors (LonamiWebs#4127)

* Support most usernames in VALID_USERNAME_RE

See LonamiWebs#4128.

* Fix lack of support for anon channel restrictions (LonamiWebs#4130)

* Improve error message when trying to delete inline messages

Closes LonamiWebs#4129.

* Change html.unparse logic to mimic markdown's

It was overcomplicated and had some subtle bugs.
Closes LonamiWebs#4133.

* Update to layer 160

* Fix reply_to can be optional

* Fix _get_thumb failed when document had no thumbs

* Remove client-side checks when editing permissions

The server should instead fail with proper RPC errors,
as the rules could change any time (and the local checks
get out of date).

* Handle sqlite3.OperationalError in update loop

* Handle FloodWaitError in update loop

Likely temporary server issues, since getDifference should
realistically not fail with flood waits. In any case,
stopping early until the problem is resolved is the correct
approach.

* Don't attempt thumb download if there is no thumb

* Disable blank issues in GitHub (LonamiWebs#4157)

* Bump to v1.29.0

* Fix handling of UpdateShortSentMessage

* Improve image compression heuristics and algorithm used (LonamiWebs#4158)

* Fix reply_to when sending albums

* Sort tlobjects before generating their listing (LonamiWebs#4163)

* Don't treat asyncio.IncompleteReadError as unhandled

The library will behave the same, but the log severity is lowered.

* Except all types of timeout error

Closes LonamiWebs#4172.

* Return marked ID from MemorySession.get_entity_rows_by_id (LonamiWebs#4177)

Otherwise the unpacking done later won't work.

* Fix `is_inline` check for `KeyboardButtonWebView` (LonamiWebs#4183)

* Make MessageBox trace logs more useful

* Fix getting_diff_for with empty set was being spammed

Because the above check used >= but the inner check >.

* Further improve MessageBox trace logging

* Only update seq if pts changed

This solves UpdateChatParticipant being missed after UpdateChat,
which seems to reliable occur when a bot is in a Chat that gets
deleted.

* Change apply_deadlines_reset micro-optimization

No need for buffer reuse in Python. It simply complicates the code.
And even then it was not as optimal as it could.

* Update to layer 161

Closes LonamiWebs#4184.

* Fix incorrect param type in apply_channel_difference (LonamiWebs#4185)

* Fix date empty (LonamiWebs#4191)

* Remove client-side check in message.edit (LonamiWebs#4195)

Fixes LonamiWebs#4193.

* Update to layer 162

* Bump to v1.30

* Fix generator for pypy (LonamiWebs#4198)

* Fix invalid date type in UpdateShort

* Fix date empty when getting difference

* Fixed sorting of markup entities with the same offsets (LonamiWebs#4201)

* Remove uses of imghdr

It's deprecated. Closes LonamiWebs#4207.

* Update to layer 164

* Update to layer 165

* Update to v1.31

* Fix file name could be lost when uploading files

Leading to invalid extension when sending photos.

* Update to layer 166

* Fix init of custom Draft after layer update

* Bump to v1.32

* Add PR template mentioning v1 is feature-frozen

Should prevent efforts like LonamiWebs#4244 going to waste in the future.

* Force filename with JPG extension after resizing

Old name does not matter, since we just encoded it as JPEG

* Retry on TimedOutError (LonamiWebs#4255)

* Conditional webbrowser import (LonamiWebs#4261)

* Update to layer 167

* Bump to v1.33

* Prioritise closing tags when sorting tags

* Fix ordering of nested entities

* Bump to v1.33.1

* 'Refactored by Sourcery'

---------

Co-authored-by: novenary <[email protected]>
Co-authored-by: Lonami <[email protected]>
Co-authored-by: iamilya <[email protected]>
Co-authored-by: Devesh Pal <[email protected]>
Co-authored-by: rozha <[email protected]>
Co-authored-by: novenary <[email protected]>
Co-authored-by: Nick80835 <[email protected]>
Co-authored-by: Bernhard M. Wiedemann <[email protected]>
Co-authored-by: Kacnep89 <[email protected]>
Co-authored-by: misuzu <[email protected]>
Co-authored-by: Shubham Kumar <[email protected]>
Co-authored-by: Non <[email protected]>
Co-authored-by: Dingyuan Wang <[email protected]>
Co-authored-by: Alexander Goryushkin <[email protected]>
Co-authored-by: mario-ttide <[email protected]>
Co-authored-by: Balázs Triszka <[email protected]>
Co-authored-by: udf <[email protected]>
Co-authored-by: Sourcery AI <>
New-dev0 added a commit to TeamUltroid/Telethon that referenced this issue Dec 12, 2023
* Change bug report template to an issue form

Lifted from Tachiyomi and adapted for Telethon.

See: https://github.com/tachiyomiorg/tachiyomi/blob/master/.github/ISSUE_TEMPLATE/report_issue.yml

* Change feature request template to an issue form

* Add dedicated form for documentation issues

* Update some fields in the GH issue template

* Fix comment_to for a group of messages (LonamiWebs#4120)

* Clarify OS field in bug report template

* Handle CancelledError inside mtprotosender recv loop

* Add missing formatting arg in logging call

Noticed in LonamiWebs#4123.

* Document more RPC errors (LonamiWebs#4127)

* Support most usernames in VALID_USERNAME_RE

See LonamiWebs#4128.

* Fix lack of support for anon channel restrictions (LonamiWebs#4130)

* Improve error message when trying to delete inline messages

Closes LonamiWebs#4129.

* Change html.unparse logic to mimic markdown's

It was overcomplicated and had some subtle bugs.
Closes LonamiWebs#4133.

* Update to layer 160

* Fix reply_to can be optional

* Fix _get_thumb failed when document had no thumbs

* Remove client-side checks when editing permissions

The server should instead fail with proper RPC errors,
as the rules could change any time (and the local checks
get out of date).

* Handle sqlite3.OperationalError in update loop

* Handle FloodWaitError in update loop

Likely temporary server issues, since getDifference should
realistically not fail with flood waits. In any case,
stopping early until the problem is resolved is the correct
approach.

* Don't attempt thumb download if there is no thumb

* Disable blank issues in GitHub (LonamiWebs#4157)

* Bump to v1.29.0

* Fix handling of UpdateShortSentMessage

* Improve image compression heuristics and algorithm used (LonamiWebs#4158)

* Fix reply_to when sending albums

* Sort tlobjects before generating their listing (LonamiWebs#4163)

* Don't treat asyncio.IncompleteReadError as unhandled

The library will behave the same, but the log severity is lowered.

* Except all types of timeout error

Closes LonamiWebs#4172.

* Return marked ID from MemorySession.get_entity_rows_by_id (LonamiWebs#4177)

Otherwise the unpacking done later won't work.

* Fix `is_inline` check for `KeyboardButtonWebView` (LonamiWebs#4183)

* Make MessageBox trace logs more useful

* Fix getting_diff_for with empty set was being spammed

Because the above check used >= but the inner check >.

* Further improve MessageBox trace logging

* Only update seq if pts changed

This solves UpdateChatParticipant being missed after UpdateChat,
which seems to reliable occur when a bot is in a Chat that gets
deleted.

* Change apply_deadlines_reset micro-optimization

No need for buffer reuse in Python. It simply complicates the code.
And even then it was not as optimal as it could.

* Update to layer 161

Closes LonamiWebs#4184.

* Fix incorrect param type in apply_channel_difference (LonamiWebs#4185)

* Fix date empty (LonamiWebs#4191)

* Remove client-side check in message.edit (LonamiWebs#4195)

Fixes LonamiWebs#4193.

* Update to layer 162

* Bump to v1.30

* Fix generator for pypy (LonamiWebs#4198)

* Fix invalid date type in UpdateShort

* Fix date empty when getting difference

* Fixed sorting of markup entities with the same offsets (LonamiWebs#4201)

* Remove uses of imghdr

It's deprecated. Closes LonamiWebs#4207.

* Update to layer 164

* Update to layer 165

* Update to v1.31

* Fix file name could be lost when uploading files

Leading to invalid extension when sending photos.

* Update to layer 166

* Fix init of custom Draft after layer update

* Bump to v1.32

* Add PR template mentioning v1 is feature-frozen

Should prevent efforts like LonamiWebs#4244 going to waste in the future.

* Force filename with JPG extension after resizing

Old name does not matter, since we just encoded it as JPEG

* Retry on TimedOutError (LonamiWebs#4255)

* Conditional webbrowser import (LonamiWebs#4261)

* Update to layer 167

* Bump to v1.33

* Prioritise closing tags when sorting tags

* Fix ordering of nested entities

* Bump to v1.33.1

* 'Refactored by Sourcery'

---------

Co-authored-by: novenary <[email protected]>
Co-authored-by: Lonami <[email protected]>
Co-authored-by: iamilya <[email protected]>
Co-authored-by: Devesh Pal <[email protected]>
Co-authored-by: rozha <[email protected]>
Co-authored-by: novenary <[email protected]>
Co-authored-by: Nick80835 <[email protected]>
Co-authored-by: Bernhard M. Wiedemann <[email protected]>
Co-authored-by: Kacnep89 <[email protected]>
Co-authored-by: misuzu <[email protected]>
Co-authored-by: Shubham Kumar <[email protected]>
Co-authored-by: Non <[email protected]>
Co-authored-by: Dingyuan Wang <[email protected]>
Co-authored-by: Alexander Goryushkin <[email protected]>
Co-authored-by: mario-ttide <[email protected]>
Co-authored-by: Balázs Triszka <[email protected]>
Co-authored-by: udf <[email protected]>
Co-authored-by: Sourcery AI <>
New-dev0 added a commit to TeamUltroid/Telethon that referenced this issue May 13, 2024
* Change bug report template to an issue form

Lifted from Tachiyomi and adapted for Telethon.

See: https://github.com/tachiyomiorg/tachiyomi/blob/master/.github/ISSUE_TEMPLATE/report_issue.yml

* Change feature request template to an issue form

* Add dedicated form for documentation issues

* Update some fields in the GH issue template

* Fix comment_to for a group of messages (LonamiWebs#4120)

* Clarify OS field in bug report template

* Handle CancelledError inside mtprotosender recv loop

* Add missing formatting arg in logging call

Noticed in LonamiWebs#4123.

* Document more RPC errors (LonamiWebs#4127)

* Support most usernames in VALID_USERNAME_RE

See LonamiWebs#4128.

* Fix lack of support for anon channel restrictions (LonamiWebs#4130)

* Improve error message when trying to delete inline messages

Closes LonamiWebs#4129.

* Change html.unparse logic to mimic markdown's

It was overcomplicated and had some subtle bugs.
Closes LonamiWebs#4133.

* Update to layer 160

* Fix reply_to can be optional

* Fix _get_thumb failed when document had no thumbs

* Remove client-side checks when editing permissions

The server should instead fail with proper RPC errors,
as the rules could change any time (and the local checks
get out of date).

* Handle sqlite3.OperationalError in update loop

* Handle FloodWaitError in update loop

Likely temporary server issues, since getDifference should
realistically not fail with flood waits. In any case,
stopping early until the problem is resolved is the correct
approach.

* Don't attempt thumb download if there is no thumb

* Disable blank issues in GitHub (LonamiWebs#4157)

* Bump to v1.29.0

* Fix handling of UpdateShortSentMessage

* Improve image compression heuristics and algorithm used (LonamiWebs#4158)

* Fix reply_to when sending albums

* Sort tlobjects before generating their listing (LonamiWebs#4163)

* Don't treat asyncio.IncompleteReadError as unhandled

The library will behave the same, but the log severity is lowered.

* Except all types of timeout error

Closes LonamiWebs#4172.

* Return marked ID from MemorySession.get_entity_rows_by_id (LonamiWebs#4177)

Otherwise the unpacking done later won't work.

* Fix `is_inline` check for `KeyboardButtonWebView` (LonamiWebs#4183)

* Make MessageBox trace logs more useful

* Fix getting_diff_for with empty set was being spammed

Because the above check used >= but the inner check >.

* Further improve MessageBox trace logging

* Only update seq if pts changed

This solves UpdateChatParticipant being missed after UpdateChat,
which seems to reliable occur when a bot is in a Chat that gets
deleted.

* Change apply_deadlines_reset micro-optimization

No need for buffer reuse in Python. It simply complicates the code.
And even then it was not as optimal as it could.

* Update to layer 161

Closes LonamiWebs#4184.

* Fix incorrect param type in apply_channel_difference (LonamiWebs#4185)

* Fix date empty (LonamiWebs#4191)

* Remove client-side check in message.edit (LonamiWebs#4195)

Fixes LonamiWebs#4193.

* Update to layer 162

* Bump to v1.30

* Fix generator for pypy (LonamiWebs#4198)

* Fix invalid date type in UpdateShort

* Fix date empty when getting difference

* Fixed sorting of markup entities with the same offsets (LonamiWebs#4201)

* Remove uses of imghdr

It's deprecated. Closes LonamiWebs#4207.

* Update to layer 164

* Update to layer 165

* Update to v1.31

* Fix file name could be lost when uploading files

Leading to invalid extension when sending photos.

* Update to layer 166

* Fix init of custom Draft after layer update

* Bump to v1.32

* Add PR template mentioning v1 is feature-frozen

Should prevent efforts like LonamiWebs#4244 going to waste in the future.

* Force filename with JPG extension after resizing

Old name does not matter, since we just encoded it as JPEG

* Retry on TimedOutError (LonamiWebs#4255)

* Conditional webbrowser import (LonamiWebs#4261)

* Update to layer 167

* Bump to v1.33

* Prioritise closing tags when sorting tags

* Fix ordering of nested entities

* Bump to v1.33.1

* Fix typo in documentation example (LonamiWebs#4277)

* Fix restriction_reason type hint (LonamiWebs#4282)

* Update to layer 169

* Update to layer 170

* Add missing saved_peer_id parameter to Message

* Add new config file for readthedocs

* Update to layer 171

* Add reply_to_chat and reply_to_sender in Message (LonamiWebs#4300)

* Update to layer 172

* 'Refactored by Sourcery'

---------

Co-authored-by: novenary <[email protected]>
Co-authored-by: Lonami <[email protected]>
Co-authored-by: iamilya <[email protected]>
Co-authored-by: Devesh Pal <[email protected]>
Co-authored-by: rozha <[email protected]>
Co-authored-by: novenary <[email protected]>
Co-authored-by: Nick80835 <[email protected]>
Co-authored-by: Bernhard M. Wiedemann <[email protected]>
Co-authored-by: Kacnep89 <[email protected]>
Co-authored-by: misuzu <[email protected]>
Co-authored-by: Shubham Kumar <[email protected]>
Co-authored-by: Non <[email protected]>
Co-authored-by: Dingyuan Wang <[email protected]>
Co-authored-by: Alexander Goryushkin <[email protected]>
Co-authored-by: mario-ttide <[email protected]>
Co-authored-by: Balázs Triszka <[email protected]>
Co-authored-by: udf <[email protected]>
Co-authored-by: Allen Calderwood <[email protected]>
Co-authored-by: Jahongir Qurbonov <[email protected]>
Co-authored-by: exovoq <[email protected]>
Co-authored-by: Sourcery AI <>
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