Skip to content
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

MultiDict does not handle None values #2842

Closed
Sympatron opened this issue Jan 25, 2024 · 1 comment · Fixed by #2843
Closed

MultiDict does not handle None values #2842

Sympatron opened this issue Jan 25, 2024 · 1 comment · Fixed by #2843

Comments

@Sympatron
Copy link
Contributor

The following code will result in a TypeError:

invalid_values = MultiDict([('a', 'x'), ('b', ''), ('d', None)])
print(invalid_values.get('a', type=int))  # None
print(invalid_values.get('b', type=int))  # None
print(invalid_values.get('c', type=int))  # None
print(invalid_values.get('d', type=int))  # TypeError

I think the expected behavior would be to return None as all other error cases do.

This happens because the following code only checks for ValueError and not other errors like TypeError:

try:
rv = type(rv)
except ValueError:
rv = default

@davidism
Copy link
Member

Handling TypeError along with ValueError there makes sense.

Sympatron added a commit to Sympatron/werkzeug that referenced this issue Jan 25, 2024
pgjones pushed a commit to Sympatron/werkzeug that referenced this issue Mar 3, 2024
TypeErrors are now handled in the same manner as ValueErrors.

fixes pallets#2842
pgjones pushed a commit that referenced this issue Mar 3, 2024
TypeErrors are now handled in the same manner as ValueErrors.

fixes #2842
@pgjones pgjones closed this as completed Mar 3, 2024
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 18, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants