Skip to content
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

Silent fail when trying to overwrite AttributeFrozenDict entry #284

Open
espenfl opened this issue Nov 15, 2019 · 3 comments
Open

Silent fail when trying to overwrite AttributeFrozenDict entry #284

espenfl opened this issue Nov 15, 2019 · 3 comments

Comments

@espenfl
Copy link
Contributor

espenfl commented Nov 15, 2019

Upon modifying input namespaces, e.g.

some_namespace = self.inputs.some_namespace
some_namespace.some_param = some_thing

Where some_namespace is an AttributeFrozenDict no error is given. It makes development a bit cumbersome on the plugin side. Maybe we can eject an error when this happens instead of not setting it and continuing?

@espenfl espenfl changed the title Silient fail when trying to overwrite AttributeFrozenDict entry Silent fail when trying to overwrite AttributeFrozenDict entry Nov 15, 2019
@sphuber
Copy link
Collaborator

sphuber commented Nov 15, 2019

This is happening within the define of a Process class? That is to say, the code snippet you wrote, is what you are typing in the define classmethod? Or somewhere else?

@espenfl
Copy link
Contributor Author

espenfl commented Nov 15, 2019

This happens somewhere else.

@sphuber
Copy link
Collaborator

sphuber commented Jun 1, 2024

This class comes from plumpy. I guess you are describing the following behavior:

In [1]: from plumpy.utils import AttributesFrozendict

In [2]: d = AttributesFrozendict({'a': 1})

In [3]: d.a = 5

In [4]: d
Out[4]: <AttributesFrozendict {'a': 1}>

This can indeed be a pitfall. The trouble is, once you call d.a, that returns the value of the key a in dictionary d, which is an integer. You then just assign 5 to it. This is the same as:

a = 5

At that point the AttributesFrozenDict is no longer part of the process. It has no knowledge of the assignment, so it can also not raise. I don't see how we would solve this. We would have to override the __getattr__ of AttributesFrozenDict to always wrap the return variable in some custom class that would somehow raise when something is assigned to it. What method would be called in this case even? Anyway, I will transfer this to plumpy as really that is where the class comes from, but I don't have a solution.

@sphuber sphuber transferred this issue from aiidateam/aiida-core Jun 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants