You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I was trying to use register_unstructure_hook to add a handle that does normal asdict style unstructuring, plus adds an extra field (a type tag). I found that it worked the first time, but subsequent execution fails.
You see it fails on the final assertion, not the first i.e. the second call behaves differently from the first, which was very surprising.
I found that I'm possibly "doing it wrong" - if I use cattr.global_converter.unstructure_attrs_asdict instead of converter.unstructure_attrs_asdict I get the intended behaviour. It's not clear to me if this is a bug or something that needs to be added to the documentation.
The text was updated successfully, but these errors were encountered:
Ah, I see the issue. The GenConverter is wired to generate and register an automatic hook in unstructure_attrs_asdict. Usually if a manual hook is registered that function will never get called, but you're calling it yourself here. That's why the first call works fine, and the other doesn't (since your manual hook gets overwritten with the generated hook).
I think this is a bug and this use case should be supported. I will look into it.
Description
I was trying to use
register_unstructure_hook
to add a handle that does normalasdict
style unstructuring, plus adds an extra field (a type tag). I found that it worked the first time, but subsequent execution fails.Test case:
You see it fails on the final assertion, not the first i.e. the second call behaves differently from the first, which was very surprising.
I found that I'm possibly "doing it wrong" - if I use
cattr.global_converter.unstructure_attrs_asdict
instead ofconverter.unstructure_attrs_asdict
I get the intended behaviour. It's not clear to me if this is a bug or something that needs to be added to the documentation.The text was updated successfully, but these errors were encountered: