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

Don't update the reminders cache if an edit fails #108

Closed
nmlorg opened this issue Aug 9, 2024 · 0 comments
Closed

Don't update the reminders cache if an edit fails #108

nmlorg opened this issue Aug 9, 2024 · 0 comments
Assignees
Labels
bug Something isn't working

Comments

@nmlorg
Copy link
Owner

nmlorg commented Aug 9, 2024

2024-08-09 00:10:00,473 INFO reminders.py:44] Running periodic.
2024-08-09 00:10:06,885 INFO reminders.py:185] Editing reminder -1001xxx/1991.
2024-08-09 00:10:07,641 INFO reminders.py:185] Editing reminder -1001xxx/588813.
2024-08-09 00:10:08,448 INFO reminders.py:185] Editing reminder -1001xxx/103827.
2024-08-09 00:10:09,294 INFO reminders.py:185] Editing reminder -1001xxx/678634.
2024-08-09 00:10:10,017 INFO reminders.py:185] Editing reminder -40xxx/3209.
2024-08-09 00:20:01,642 INFO reminders.py:44] Running periodic.
2024-08-09 00:20:12,006 INFO reminders.py:185] Editing reminder -1001xxx/1991.
2024-08-09 00:20:14,872 ERROR reminders.py:199] While editing 1991 in -1001xxx:
There are a bunch of events coming up:

⋮
Traceback (most recent call last):
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 188, in reminder_edit
    return bot.edit_message_caption(chat_id=groupid,
  File "lib/python3.10/site-packages/ntelebot/bot.py", line 71, in __call__
    raise ntelebot.errors.Error(data)
ntelebot.errors.Error: {'ok': False, 'error_code': 400, 'description': 'Bad Request: message is not modified: specified new message content and reply markup are exactly the same as a current content and reply markup of the message'}
2024-08-09 00:30:04,334 INFO reminders.py:44] Running periodic.
2024-08-09 00:30:12,429 ERROR loop.py:72] Ignoring uncaught error while dispatching:
Traceback (most recent call last):
  File "lib/python3.10/site-packages/ntelebot/loop.py", line 70, in run
    callback()
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 47, in periodic
    _daily_messages(multibot, records)
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 152, in _daily_messages
    message = reminder_edit(bot, groupid, last.message['message_id'], newtext,
TypeError: 'NoneType' object is not subscriptable
2024-08-09 00:40:04,992 INFO reminders.py:44] Running periodic.
2024-08-09 00:40:10,887 ERROR loop.py:72] Ignoring uncaught error while dispatching:
Traceback (most recent call last):
  File "lib/python3.10/site-packages/ntelebot/loop.py", line 70, in run
    callback()
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 47, in periodic
    _daily_messages(multibot, records)
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 152, in _daily_messages
    message = reminder_edit(bot, groupid, last.message['message_id'], newtext,
TypeError: 'NoneType' object is not subscriptable

⋮

2024-08-09 07:00:00,618 INFO reminders.py:44] Running periodic.
2024-08-09 07:00:13,345 INFO reminders.py:161] Sending reminder to -1001xxx.
2024-08-09 07:00:14,305 ERROR loop.py:72] Ignoring uncaught error while dispatching:
Traceback (most recent call last):
  File "lib/python3.10/site-packages/ntelebot/loop.py", line 70, in run
    callback()
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 47, in periodic
    _daily_messages(multibot, records)
  File "lib/python3.10/site-packages/metabot/modules/reminders.py", line 119, in _daily_messages
    reminder_edit(bot, groupid, last.message['message_id'], text,
TypeError: 'NoneType' object is not subscriptable
2024-08-09 07:10:03,276 INFO reminders.py:44] Running periodic.
2024-08-09 07:10:09,633 INFO reminders.py:185] Editing reminder -1001xxx/1992.
2024-08-09 07:10:10,412 INFO reminders.py:161] Sending reminder to -1001xxx.
2024-08-09 07:10:14,742 INFO reminders.py:185] Editing reminder -1001xxx/588813.
2024-08-09 07:10:15,620 INFO reminders.py:161] Sending reminder to -1001xxx.
2024-08-09 07:10:16,417 INFO reminders.py:185] Editing reminder -1001xxx/103827.
2024-08-09 07:10:22,358 INFO reminders.py:185] Editing reminder -1001xxx/678634.

message = reminder_edit(bot, groupid, last.message['message_id'], newtext,
last.message.get('caption'))
records[key] = (last.time, [event.copy() for event in events], message, text,
suffix)

If editMessageText/editMessageCaption fails, reminder_edit returns None, which gets written into config/daily.pickle, then all future attempts to dereference last.message['message_id'] will fail.

This used to be prevented by simply checking if message is truthy before updating config/daily.pickle:

if message:
records[key] = (eventtime, [event.copy() for event in events], message, text,
suffix)

@nmlorg nmlorg added the bug Something isn't working label Aug 9, 2024
@nmlorg nmlorg self-assigned this Aug 9, 2024
nmlorg added a commit that referenced this issue Aug 10, 2024
…t be treated as a successful action (see #108).

Release as 0.3.25.1.
@nmlorg nmlorg closed this as completed Aug 10, 2024
nmlorg added a commit to nmlorg/ntelebot that referenced this issue Aug 11, 2024
…modified).

Send a message to a test chat, modify it, try to modify it with the same text again (verifying ntelebot.errors.Unmodified is raised), then delete it.

See nmlorg/metabot#108.
nmlorg added a commit that referenced this issue Aug 11, 2024
…as if Telegram returned it as a result of a successful edit.

This is not strictly correct — lastmessage['text'] will not contain the new text (etc.) — but is arguably better than treating an Unmodified as a failure (triggering another attempt to edit next run).

See #108.

Release as 0.3.25.2.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant