-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
TypeError when calling asdict() on a dataclass containing Certificates #5129
Comments
Serializing and re-parsing is the right path for generating a new Certificate object like this. However, to be safe you should use the I'm reluctant to land code like this in |
Defining an |
Thanks! |
I am using Python 3.7's dataclasses to pass around data, including certificates parsed using
cryptography.x509.load_pem_x509_certificate()
. The dataclass module has a utility function calledasdict()
which turns a dataclass into a Python dictionary with the same fields (https://docs.python.org/3/library/dataclasses.html#dataclasses.asdict).When calling
asdict()
on a dataclass instance that contains a Certificate, it crashes. The fix I found was to add a__deepcopy__()
method to the Certificate class (specificallycryptography.hazmat.backends.openssl.x509._Certificate
).I don't know if the lack of support for
__deepcopy__()
is by design or not. If not I'd be willing to create a pull request with the fix (but I don't really understand all the implications of adding the__deepcopy__()
method to this class).Steps to reproduce:
The following file contains a test case that will trigger the crash and a test case with the fix:
The stack trace for the crash is the following:
The text was updated successfully, but these errors were encountered: