Skip to content

Fixed error overlapping when validation error is caused by remove_unset root validator in base types and methods. #1290

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 4 commits into from
Aug 28, 2023

Conversation

JrooTJunior
Copy link
Member

Description

Fixed error overlapping when validation error is caused by remove_unset root validator in base types and methods.

Example:

InlineKeyboardButton(
    text="Play with Friends",
    switch_inline_query_chosen_chat="test",
)

Caused:

  .../aiogram/types/base.py", line 31, in remove_unset
    return {k: v for k, v in values.items() if not isinstance(v, UNSET_TYPE)}
AttributeError: 'str' object has no attribute 'items'                                                                                                                      

Expected:

pydantic_core._pydantic_core.ValidationError: 1 validation error for InlineKeyboardButton
switch_inline_query_chosen_chat
  Input should be a valid dictionary or instance of SwitchInlineQueryChosenChat [type=model_type, input_value='test', input_type=str]
    For further information visit https://errors.pydantic.dev/2.1/v/model_type

The update introduces a condition to verify whether the values being validated are a dictionary before attempting to handle UNSET_TYPE in the aiogram base type. This adjustment helps to prevent potential errors or incorrect validation when non-dictionary values are faced.
@JrooTJunior JrooTJunior added bug Something is wrong with the framework 3.x Issue or PR for stable 3.x version labels Aug 28, 2023
@JrooTJunior JrooTJunior added this to the 3.0 milestone Aug 28, 2023
@github-actions
Copy link

github-actions bot commented Aug 28, 2023

✔️ Changelog found.

Thank you for adding a description of the changes

@JrooTJunior JrooTJunior changed the title Remove unset issue Fixed error overlapping when validation error is caused by remove_unset root validator in base types and methods. Aug 28, 2023
@codecov
Copy link

codecov bot commented Aug 28, 2023

Codecov Report

Merging #1290 (639c058) into dev-3.x (e1be9dd) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##           dev-3.x     #1290   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          367       367           
  Lines         9350      9354    +4     
=========================================
+ Hits          9350      9354    +4     
Flag Coverage Δ
unittests 100.00% <100.00%> (ø)

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

Files Changed Coverage Δ
aiogram/methods/base.py 100.00% <100.00%> (ø)
aiogram/types/base.py 100.00% <100.00%> (ø)

@JrooTJunior JrooTJunior merged commit 04bd0c9 into dev-3.x Aug 28, 2023
@JrooTJunior JrooTJunior deleted the remove-unset-issue branch September 24, 2024 00:17
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 bug Something is wrong with the framework
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

1 participant