duo-labs / py_webauthn

Pythonic WebAuthn 🐍
https://duo-labs.github.io/py_webauthn
BSD 3-Clause "New" or "Revised" License
856 stars 171 forks source link

Pydantic/bytes validation doesn't accept Python memoryview #119

Closed jwag956 closed 2 years ago

jwag956 commented 2 years ago

The latest version going back to pydantic with a custom 'bytes' validation class still throws an error during runtime validation in the case of peewee+postresql.

In this case - a python memoryview type is being returned. That should also be 'ok' as being bytes. It seems like it would be very simple to extend the BytesLike validator to handle this case.

Note: the original mongodb issue - which subclassed 'bytes' works fine....

MasterKale commented 2 years ago

@jwag956 Thank you for the report! I'm lucky to have you and your ability to find (and endure?) these compatibility issues 🙇

Okay, so seeing that the CustomBytes in tests/test_bytes_subclass_support.py calls .tobytes() on a memoryview it uses, I suppose it'd be sufficient to add the following elif to BytesLike.validate():

elif isinstance(v, memoryview):
    return v.tobytes()

I'll give this a try in the morning.

jwag956 commented 2 years ago

Yup - I think that's all it will take.

thanks!

MasterKale commented 2 years ago

@jwag956 This should be fixed in the newly published webauthn==1.4.0 🚀