-
Notifications
You must be signed in to change notification settings - Fork 64
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
Inconsistent Delete Behavior #246
Comments
Digging into it deeper, I've figured out that when it fails, it's because here |
I suspect what is happening here is that Here's a quick example script, you can see as long as we use a fresh input it works, but if we re-use the same data structure twice we get that exact error. from collections import OrderedDict
import glom
def build():
return OrderedDict([
('name', 'dog'),
('test', '12345'),
('inputs', OrderedDict([
('animal', 'cat'),
('test-value', 'test'),
])),
('test2', [OrderedDict([
('name', 'dog2')
])])
])
glom.delete(build(), "inputs.animal")
glom.delete(build(), "inputs.animal")
glom.delete(build(), "inputs.animal")
test = build()
glom.delete(test, "inputs.animal")
glom.delete(test, "inputs.animal") You mentioned this was a minimization of an error in a more complex case. Maybe the original case is different? Also, does |
@kurtbrose So in my actual use case we are reading in a YAML file and modifying it with glom to delete stuff and then dumping it back. I noticed sometimes it would update and sometimes it wouldn't and it's because I had ignore missing set to true which was masking the error of it not finding the element even though it existed. In my script example above, I was actually just straight running that exact script over and over and sometimes it would fail and sometimes it wouldn't but as you can see, I'm not using the same dictionary. Start of the script we initialize Out of curiosity, did you run my example above? I'm curious if you can replicate it. I actually decided to try this on my home computer running Windows and using the Windows Subsystem for Linux and I can't get it to fail. When it was failing before, it was on a Macbook and the other people who tested it for me were also running Mac, so it makes me wonder if some weird memory or caching issue with Mac and running the script. |
Hey! So I tried this back in November and had no luck, but now on 3.10 I think I've repro'd the behavior! It's super late here, and the issue is super funky, so forgive these rough notes. First, a bit about my repro. When the script above is run with Next: Quick fix. Explicitly register the OrderedDict type here. We'd been relying on At the moment, when glom encounters a type that it doesn't recognize, it tries to find the closest type it knows about. Then it attempts to use the operation handler associated with that. This has two implications:
More importantly:
Anyways, super interesting bug, thanks for reporting it and making such a great minimal case! This was a tough one to report and I'm really glad you did. I'll push the quick fix for OD momentarily, for release with glom 23 this week. Deeper fix to follow. Thanks again! |
Oops, I see now I missed in the original report: got error: AttributeError('animal') That means it was trying to do A temporary work-around would be to use a glom.delete(test, T["inputs"]["animal"]) |
Version:
22.1.0
I noticed in my larger script inconsistent behavior where it was throwing an error deleting when it shouldn't, so I recreated a smaller example:
If I run this over and over, sometimes it works and sometimes it doesn't and throws an error
Which doesn't make any sense. it successfully prints out what is at
inputs.animal
but fails then to delete that path and it's inconsistent. Out of 10 runs in a row, 3 of them failed for deleting.I tried version
20.11.0
too out of curiosity and it didn't seem to change anything.The text was updated successfully, but these errors were encountered: