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

serializer_kwargs are missing in load_payload function #389

Open
alexeykomp opened this issue Jun 2, 2024 · 0 comments
Open

serializer_kwargs are missing in load_payload function #389

alexeykomp opened this issue Jun 2, 2024 · 0 comments

Comments

@alexeykomp
Copy link

alexeykomp commented Jun 2, 2024

When using this library with a serializer, it's sometimes necessary to provide the serializer with additional kwargs. It works great within the dump_payload function. However, load_payload function doesn't supply any stored serializer_kwargs into the serializer. I'm not sure if it's done intentionally or just forgotten.

Here's the code to reproduce the problem:

import jsonpickle
from itsdangerous import Serializer

key = '123'
data = {0: 'foo', 1: "bar"}
s = Serializer(key, serializer=jsonpickle, serializer_kwargs={"keys": True})

signed = s.dumps(data)
unsigned = s.loads(signed)
print(unsigned)  
# {'json://0': 'foo', 'json://1': 'bar'} - because the kwarg "keys": True was not overhanded to the loading function

The expected behavior would be to provide load_payload with **serializer_kwargs and return {0: 'foo', 1: 'bar'} in this example.

I personally opted to have separate Serializer instances for dumping and loading processes, but may it be smarter to implement a separate "deserializer_kwargs" parameter?
I see the problem that serializer_kwargs may require to be different for serializing and deserializing - that's why my suggested solution (straight-forward overhanding of serializer_kwargs into deserializer function) doesn't pass the existing tests.

Environment:

  • Python version: 3.12
  • ItsDangerous version: 2.2.0
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant