-
Notifications
You must be signed in to change notification settings - Fork 12
Attributes of fields defined at the class level should not be shared between instances #325
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
Comments
This comment was marked as resolved.
This comment was marked as resolved.
Thanks @denisri for the tip! I have made the change to use a temporary local database as you suggested. Unfortunately, this did not fix the original issue. I noticed that it is always the same two tests that are consistently failing ( By the way, since using a temporary database I am getting messages printed to my terminal asynchronously ( |
I made some progress and characterized the bug a bit more precisely: it happens when certain processes are run in a certain order. For instance, running
It behaves as if the |
This comment was marked as outdated.
This comment was marked as outdated.
I did not take time to look at your pipelines yet, but this definitely looks like a bug in Capsul. |
Found it! And yes @denisri you guessed it right: the problem is that when I call I am using class-level attributes and not instance attributes, because I thought that it was more in line with the philosophy behind traits / pydantic typing. Isn't there a way that we could store instance-level attributes? Maybe the typing |
OK, then at least we understand.
Maybe not, it's just convenient and easy to do it this way. Another way would probably require some additional development. |
In v3, metadata are obtained from the Field instances and for class fields they are stored in class and therefore shared with all instances. It would not be easy to change the API to get metadata from controller instance since metadata are used in many places and can be read/modified by direct attribute access and there is no obvious method to find in code. So, one option would be to copy all class fields into Process instances during construction. I have the feeling that it may use too much resource for big pipelines but I am not absolutely sure. Another option could be to make class fields read-only (to avoid users to have the same kind of problem one day), to allow explicit copy of a class fields into an instance field to make it read-write and to store |
The copy to instance mechanism can be a solution, and could be done on demand, only for fields for which we want to change metadata. So yes why not. We would need an easy copy function, like |
This issue should be fixed by two PR, populse/soma-base#53 and #326. Controller class fields are now read-only and process instantiation copy them to instance field. It was too difficult to make something smarter by copying fields only when they need to be modified. |
#325 adaptation for read-only class fields
populse/capsul#325 has been fixed, remove the workaround
I confirm that the original issue is fixed for me, thanks! |
Uh oh!
There was an error while loading. Please reload this page.
I am having trouble with the Capsul tests for highres-cortex:
when I test each process or pipeline separately all works as expected
but, whenever I run the whole test suite, I get random failures
The problem is that when I call highres_cortex.capsul.processes.Laplacian after is has been run as part of a pipeline, its fields retain the generate_temporary attribute!
I am using class-level attributes and not instance attributes, because I thought that it was more in line with the philosophy behind traits / pydantic typing.
The text was updated successfully, but these errors were encountered: