Skip to content

FIX TelegramObject.__setitem__ #532

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

Merged
merged 5 commits into from
Mar 21, 2021
Merged

FIX TelegramObject.__setitem__ #532

merged 5 commits into from
Mar 21, 2021

Conversation

andrew000
Copy link
Contributor

@andrew000 andrew000 commented Mar 19, 2021

Removed 'raise KeyError(key)'

Description

Fix error:

  File "/usr/local/lib/python3.8/dist-packages/aiogram/types/chat.py", line 112, in get_url
    await self.update_chat()
  File "/usr/local/lib/python3.8/dist-packages/aiogram/types/chat.py", line 124, in update_chat
    self[key] = value
  File "/usr/local/lib/python3.8/dist-packages/aiogram/types/base.py", line 228, in __setitem__
    raise KeyError(key)
KeyError: 'message_auto_delete_time'

Fixes # (issue)

Type of change

Please delete options that are not relevant.

  • Bug fix (non-breaking change which fixes an issue)

How Has This Been Tested?

Please describe the tests that you ran to verify your changes. Provide instructions so we can reproduce. Please also list any relevant details for your test configuration

  • Test with Update that raises this error
  • Test using await msg.chat.update_chat()

Test Configuration:

  • Operating System: Windows 10, Ubuntu 20.04.2 LTS
  • Python version: 3.8.5, 3.8.7

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • My changes generate no new warnings
  • New and existing unit tests pass locally with my changes

Removed 'raise KeyError(key)'
Copy link
Contributor

@Olegt0rr Olegt0rr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not a fix, you're trying to brake validator instead

@evgfilim1 evgfilim1 added the bug Something is wrong with the framework label Mar 20, 2021
@evgfilim1
Copy link
Contributor

@Olegt0rr I guess that's intended "breakage". Look at this commit: 75222b8. And look at the file.
Doesn't it seem useless to assign a value then raise KeyError?

Copy link
Contributor

@evgfilim1 evgfilim1 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, thanks for PR!

@evgfilim1 evgfilim1 added this to the 2.12.1 milestone Mar 20, 2021
@Olegt0rr
Copy link
Contributor

Olegt0rr commented Mar 20, 2021

Doesn't it seem useless to assign a value then raise KeyError?

raise KeyError(key) line helps us to find #534
If we'll accept this PR, next time on a similar silent API update we'll miss a field again

Suggestion: We may use warning instead of KeyError

@Olegt0rr Olegt0rr added under discussion A subject of discussion and removed bug Something is wrong with the framework labels Mar 20, 2021
When Telegram adds a new field -> Aiogram will warn about this.
@andrew000
Copy link
Contributor Author

Commit: d34e9c2

Example of warning in CLI:

aiogram\aiogram\types\base.py:230: UserWarning: Field 'message_auto_delete_time' doesn't exist in <class 'aiogram.types.chat.Chat'>
  warnings.warn(f"Field '{key}' doesn't exist in {self.__class__}")

Example of warning in log flie:
{aiogram\aiogram\types\base.py:231} 2021-03-20 15:38:35,275 - WARNING - Field 'message_auto_delete_time' doesn't exist in <class 'aiogram.types.chat.Chat'>

@andrew000 andrew000 requested a review from Olegt0rr March 20, 2021 13:50
@andrew000 andrew000 requested a review from Olegt0rr March 20, 2021 18:05
@Olegt0rr Olegt0rr added enhancement Make it better! and removed under discussion A subject of discussion labels Mar 20, 2021
@andrew000 andrew000 requested a review from Olegt0rr March 20, 2021 18:19
@JrooTJunior JrooTJunior merged commit b0f2fe3 into aiogram:dev-2.x Mar 21, 2021
@andrew000 andrew000 deleted the fix-base-_setitem_ branch March 21, 2021 12:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Make it better!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants