Visitar URL original
MultiDict converts byte values to int list since version 3.1.0 · Issue #2994 · pallets/werkzeug · GitHub
Skip to content

MultiDict converts byte values to int list since version 3.1.0 #2994

Closed

Description

@ricky-provan

Since version 3.1.0, when I create a MultiDict with a bytes value as input it stores the bytes value in the MultiDict as a list of integer values. Prior to 3.1.0, this would preserve the bytes value in the MultiDict.

To reproduce, run this snippet with werkzeug installed:

from werkzeug.datastructures import MultiDict

multi_dict = MultiDict({
    'bytes_value': b'abc',
    'str_value': 'abc'
})

print(multi_dict)

Running the above on version 3.1.0 prints:
MultiDict([('bytes_value', 97), ('bytes_value', 98), ('bytes_value', 99), ('str_value', 'abc')])

Running the snippet with version 3.0.6 prints:
MultiDict([('bytes_value', b'abc'), ('str_value', 'abc')])

I expected the behaviour from 3.0.6 to be preserved in this case

Environment:

  • Python version: 3.11
  • Werkzeug version: >= 3.1.0

Activity

  1. added this to the 3.1.3 milestone on Nov 6, 2024
  2. davidism commented on Nov 6, 2024

    @davidism
    Member

    I switched to isinstance(value, Collection) and not isinstance(value, str) instead of isinstance(value, (list, tuple)), in order to accept more types of iterable data. However, bytes, bytearray, memoryview, and probably other types that shouldn't be treated as multiple values, are also matched by that. I think I might switch back to the (list, tuple) check.

  3. locked as resolved and limited conversation to collaborators on Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions