Skip to content

Fix handling of default empty string ("") in CallbackData filter#1493

Merged
JrooTJunior merged 15 commits intoaiogram:dev-3.xfrom
m-xim:dev-3.x
Mar 10, 2025
Merged

Fix handling of default empty string ("") in CallbackData filter#1493
JrooTJunior merged 15 commits intoaiogram:dev-3.xfrom
m-xim:dev-3.x

Conversation

@m-xim
Copy link
Contributor

@m-xim m-xim commented May 26, 2024

Fix handling of default empty string ("") in CallbackData filter.

Description

Previously, the filter did not activate if a field in the CallbackData class had a default value set to an empty string (""). This update fixes that behavior, ensuring the filter functions correctly in such cases.

Type of change

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

How Has This Been Tested?

from aiogram import Router, F
from aiogram.filters.callback_data import CallbackData
from aiogram.types import CallbackQuery


class MyCallbackData(CallbackData, prefix="MyCallbackData"):
    input1: str
    input2: str = ""


router = Router()


@router.callback_query(MyCallbackData.filter(F.input1 == "demo"))
async def my_callback(query: CallbackQuery, callback_data: MyCallbackData):

    print("input2 =", callback_data.input2)

Test Configuration:

  • Operating System: Windows 10
  • Python version: 3.12.2

Checklist:

  • My code follows the style guidelines of this project
  • I have performed a self-review of my own code
  • I have made corresponding changes to the documentation
  • I have added tests that prove my fix is effective or that my feature works
  • New and existing unit tests pass locally with my changes

Allows using a default value in the class which is equal to an empty string ("").

Example:
class MyCallbackData(CallbackData, prefix="MyCallbackData"):
    input1: str
    input2: str = ""
@github-actions github-actions bot added the 3.x Issue or PR for stable 3.x version label May 26, 2024
@github-actions
Copy link

github-actions bot commented May 26, 2024

✔️ Changelog found.

Thank you for adding a description of the changes

@m-xim m-xim changed the title Update callback_data.py Allows using a default value in the class which is equal to an empty string ("") May 26, 2024
Fixed an issue that prevented unpacking None values.
@JrooTJunior
Copy link
Member

Please merge branch dev-3.x into your branch.

@codecov
Copy link

codecov bot commented May 28, 2024

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 100.00%. Comparing base (e17c841) to head (391188e).
Report is 11 commits behind head on dev-3.x.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1493   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          485       485           
  Lines        12251     12252    +1     
=========================================
+ Hits         12251     12252    +1     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
aiogram/filters/callback_data.py 100.00% <100.00%> (ø)
🚀 New features to boost your workflow:
  • Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@JrooTJunior JrooTJunior left a comment

Choose a reason for hiding this comment

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

Please add tests that cover your changes

@m-xim m-xim requested a review from JrooTJunior June 10, 2024 03:22
@m-xim m-xim requested a review from Olegt0rr January 2, 2025 13:42
@m-xim m-xim changed the title Allows using a default value in the class which is equal to an empty string ("") Fix handling of default empty string ("") in CallbackData filter Feb 13, 2025
@m-xim
Copy link
Contributor Author

m-xim commented Feb 20, 2025

Hello @JrooTJunior, @Olegt0rr,

I've updated the PR with the requested changes. Please review it and let me know if any further adjustments are needed.

Thank you!

@JrooTJunior JrooTJunior merged commit 658f1fc into aiogram:dev-3.x Mar 10, 2025
23 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3.x Issue or PR for stable 3.x version

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants