Skip to content

Fix CallbackData without default Optional - #1370

Merged
JrooTJunior merged 4 commits into
dev-3.xfrom
fixes/callbackdata-null-value
Nov 20, 2023
Merged

Fix CallbackData without default Optional#1370
JrooTJunior merged 4 commits into
dev-3.xfrom
fixes/callbackdata-null-value

Conversation

@Olegt0rr

@Olegt0rr Olegt0rr commented Nov 20, 2023

Copy link
Copy Markdown
Contributor

Description

Fixes #1368

Method .is_required() returns True on Optional[int] without default value, because it's still requires either int or None value.
On the other hand, when we parse a value from a zero-length string - it cannot be converted to None or an int, so pyantic returns an error about it.

The solution to this problem is to adapt the field type check to such a case.

@github-actions github-actions Bot added the 3.x Issue or PR for stable 3.x version label Nov 20, 2023
@github-actions

github-actions Bot commented Nov 20, 2023

Copy link
Copy Markdown

✔️ Changelog found.

Thank you for adding a description of the changes

@codecov

codecov Bot commented Nov 20, 2023

Copy link
Copy Markdown

Codecov Report

Merging #1370 (22f10a8) into dev-3.x (ebade3d) will not change coverage.
The diff coverage is 100.00%.

Additional details and impacted files

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1370   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          369       369           
  Lines         9449      9455    +6     
=========================================
+ Hits          9449      9455    +6     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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

Files Coverage Δ
aiogram/__init__.py 100.00% <100.00%> (ø)
aiogram/filters/callback_data.py 100.00% <100.00%> (ø)

@Olegt0rr
Olegt0rr marked this pull request as ready for review November 20, 2023 09:09
@Olegt0rr
Olegt0rr requested review from a team and JrooTJunior November 20, 2023 09:09
Comment thread aiogram/filters/callback_data.py Outdated
This update extends the callback data handling by adding support for nullable fields. The code now uses the Python typing structures `Optional` and `Union` to parse such fields correctly. A helper function `_check_field_is_nullable` has been added to assist in efficiently checking if a given field is nullable.
This update extends the callback data handling by adding support for nullable fields. The code now uses the Python typing structures `Optional` and `Union` to parse such fields correctly. A helper function `_check_field_is_nullable` has been added to assist in efficiently checking if a given field is nullable.
@JrooTJunior
JrooTJunior merged commit e17e3bc into dev-3.x Nov 20, 2023
@Olegt0rr
Olegt0rr deleted the fixes/callbackdata-null-value branch November 21, 2023 12:12
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.

Can`t unpack None value in CallbackData

2 participants