-
Notifications
You must be signed in to change notification settings - Fork 69
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
Fix JSON serialization of ValueEnum
s
#944
Conversation
ValueEnum
classValueEnum
s
ValueEnum
sValueEnum
s
I will never end the crusade against custom |
Hey I think this broke atomate2, see this atomate2 issue which I've reproduced with emmet>=0.78.0, and couldn't reproduce with emmet<=0.77.1 |
It's probably better to solve the root cause of the problem in atomate2 (or monty, if relevant) rather than patch back in a custom |
Maybe I'm missing something, but this PR changed the behaviour of these objects. That doesn't seem like an atomate2 issue as we were using these objects as intended. The docstring specifies that ValueEnum should serialise to a string. |
There's a |
The point is that we want to serialise these objects as strings. That's why we were using ValueEnum. I'd ask if you want to have enums that serialise as dicts then please just use regular Enums (now supported in monty). |
I guess there are a few things to unpack here. In emmet, and therefore in atomate2 and other packages, there are a few objects inheriting from The I suppose the question to ask is there a better way to achieve the desired Now that the situation is a bit clearer to me and we also see some of the downstream effects, perhaps the better approach would simply be to re-add the |
I think this PR and issue #914 are misunderstanding what from monty.serialization import dumpfn
from emmet.core.symmetry import CrystalSystem
sym = CrystalSystem("Triclinic")
dumpfn(sym, "test.json") is not an issue in itself. E.g., the following code does not mean that string serialisation is broken: dumpfn("Triclinic", "test.json") # will fail The goal of {
"crystal_system": "Triclinic"
} rather than {
"crystal_system": {
"@module": "emmet.core.utils",
"@class": "ValueEnum",
"value": "Triclinic",
}
} The latter makes it convoluted to query the task document easily. Perhaps there is a better way to achieve this and I agree that the To summarise, the issue raised in #914 is not a bug it is the intended behaviour as per the docstring and existing usage. This change has broken atomate2 and other downstream packages. Please can we revert it. |
ValueEnum
sValueEnum
s
Closes #914.
This now works.