#1281 Fix magic operation .as_ for values interpreted as False

Modified the ".as_" method in the magic filter class to correctly handle values that are interpreted as `False` such as `0`. Previously, the method incorrectly dismissed these valid values. The issue was identified and fixed to ensure correct handling of all valid data inputs.
This commit is contained in:
Alex Root Junior 2023-08-26 22:29:23 +03:00
parent b7be9c2b81
commit abd262824d
No known key found for this signature in database
GPG key ID: 074C1D455EBEA4AC
3 changed files with 17 additions and 2 deletions

View file

@ -19,3 +19,17 @@ class TestMagicFilter:
result = magic.resolve(MyObject(text="123"))
assert isinstance(result, dict)
assert isinstance(result["match"], Match)
def test_operation_as_not_none(self):
# Issue: https://github.com/aiogram/aiogram/issues/1281
magic = F.cast(int).as_("value")
result = magic.resolve("0")
assert result == {"value": 0}
def test_operation_as_not_none_iterable(self):
# Issue: https://github.com/aiogram/aiogram/issues/1281
magic = F.as_("value")
result = magic.resolve([])
assert result is None