Skip to content

Return False from async text filters when the message has no text - #2650

Open
youdie006 wants to merge 1 commit into
eternnoir:masterfrom
youdie006:async-text-filters-no-text
Open

youdie006 wants to merge 1 commit into
eternnoir:masterfrom
youdie006:async-text-filters-no-text

Conversation

@youdie006

Copy link
Copy Markdown

Description

#2645 made the sync TextContainsFilter, TextStartsFilter and IsDigitFilter return False when the message has no text, and the sync TextFilter already did. The asyncio_filters versions still raise on such a message (TypeError: argument of type 'NoneType' is not iterable, AttributeError: 'NoneType' object has no attribute 'startswith', ...). In AsyncTeleBot that exception skips the rest of the handlers for the update:

@bot.message_handler(content_types=["photo"], text=asyncio_filters.TextFilter(contains=["#cat"]))
async def on_cat_photo(message): ...

@bot.message_handler(content_types=["photo"])
async def on_any_photo(message): ...

A photo without a caption goes to the exception handler with a TypeError instead of reaching on_any_photo; TeleBot with the same handlers calls on_any_photo. This adds the same None checks to the four async filters.

Describe your tests

Two tests in tests/test_custom_filters.py, next to the sync ones from #2645, using its fixtures; the first fails without the change. cd tests && py.test: 309 passed, 73 skipped (the token-dependent tests).

Python version: 3.11 and 3.14

OS: Linux

Checklist:

  • I added/edited example on new feature/change (if exists)
  • My changes won't break backward compatibility
  • I made changes both for sync and async

Written with AI assistance (Claude); I have reviewed the change.

eternnoir#2645 added the 'no text' guard to the sync TextContainsFilter, TextStartsFilter and IsDigitFilter, and an older change added it to the sync TextFilter. The asyncio_filters versions still raise on a message with neither text nor caption, which aborts the remaining handlers for that update.
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

Successfully merging this pull request may close these issues.

1 participant