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

ProcessBuilder: ensure instances do not interfere #4984

Conversation

sphuber
Copy link
Contributor

@sphuber sphuber commented Jun 11, 2021

Fixes #4420

There was a bug in the ProcessBuilderNamespace constructor where it
converts the ports of the port namespace into dynamic properties and
assigns them to the class. The problem here is that the property is
added to the class instead of the instance. This meant that if you have
two classes that happen to have ports with overlapping names, when
constructing the builder for the second, the properties of the first
builder that have port names.

The simple solution of simply add the dynamic properties to the instance
instead of the class won't work, because properties are descriptors and
can only be assigned to a class. The workaround is to create a subclass
on the fly and attach the properties to that new class.

@sphuber sphuber added the pr/blocked PR is blocked by another PR that should be merged first label Jun 11, 2021
@codecov
Copy link

codecov bot commented Jun 11, 2021

Codecov Report

Merging #4984 (d9f4940) into develop (59cee4a) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@             Coverage Diff             @@
##           develop    #4984      +/-   ##
===========================================
- Coverage    80.38%   80.38%   -0.00%     
===========================================
  Files          529      529              
  Lines        36862    36867       +5     
===========================================
+ Hits         29628    29632       +4     
- Misses        7234     7235       +1     
Flag Coverage Δ
django 74.88% <100.00%> (+0.01%) ⬆️
sqlalchemy 73.79% <100.00%> (+0.01%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Impacted Files Coverage Δ
aiida/engine/processes/builder.py 92.99% <100.00%> (+0.33%) ⬆️
aiida/transports/plugins/local.py 81.41% <0.00%> (-0.25%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 59cee4a...d9f4940. Read the comment docs.

@chrisjsewell
Copy link
Member

I take it this is built on (and requires first merging) #4983?

@sphuber
Copy link
Contributor Author

sphuber commented Jun 16, 2021

I take it this is built on (and requires first merging) #4983?

It does indeed. The changes in this PR are minimal and can already be reviewed, but it is not the easiest to distill them from the other changes. Thats why I marked it blocked so we can merge the other first and then this should be straightforward

@sphuber sphuber force-pushed the fix/4420/process-builder-instance-interference branch from f97b216 to 188a988 Compare June 21, 2021 08:40
@sphuber sphuber removed the pr/blocked PR is blocked by another PR that should be merged first label Jun 21, 2021
@sphuber sphuber requested review from greschd and chrisjsewell June 21, 2021 08:41
@sphuber sphuber force-pushed the fix/4420/process-builder-instance-interference branch from 188a988 to 12fdfae Compare July 8, 2021 10:05
@chrisjsewell chrisjsewell self-assigned this Jul 21, 2021
@chrisjsewell
Copy link
Member

chrisjsewell commented Jul 28, 2021

ugghh, this doesn't look quite kosher lol. Are sure we cannot use __getattr__ here? (as already mentioned in #4420 (comment))

@sphuber
Copy link
Contributor Author

sphuber commented Jul 28, 2021

ugghh, this does look kosher lol.

I think you mean doesn't ?

Are sure we cannot use __getattr__ here? (as already mentioned in #4420 (comment))

Feel free to try. But with the properties we can get add the help string of the port to the __doc__ of the property. Don't think we can emulate this behavior using __getattr__.

@sphuber
Copy link
Contributor Author

sphuber commented Aug 11, 2021

@chrisjsewell I am merging this tomorrow. So if you still want to have a look at another solution, please do so a.s.a.p.

@chrisjsewell
Copy link
Member

So if you still want to have a look at another solution, please do so a.s.a.p.

ok gimme til midday tomorrow

There was a bug in the `ProcessBuilderNamespace` constructor where it
converts the ports of the port namespace into dynamic properties and
assigns them to the class. The problem here is that the property is
added to the class instead of the instance. This meant that if you have
two classes that happen to have ports with overlapping names, when
constructing the builder for the second, the properties of the first
builder that have port names.

The simple solution of simply add the dynamic properties to the instance
instead of the class won't work, because properties are descriptors and
can only be assigned to a class. The workaround is to create a subclass
on the fly and attach the properties to that new class.
@chrisjsewell chrisjsewell force-pushed the fix/4420/process-builder-instance-interference branch from 12fdfae to d9f4940 Compare August 11, 2021 17:38
Copy link
Member

@chrisjsewell chrisjsewell left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, ok I'll approve this.

I get that the dynamic attribute access help in the context of ipython shells, but urgh, it does feel these builders are getting overly complex.
Then again, I don't have a better solution right now 🤷

@sphuber sphuber merged commit efd1c3d into aiidateam:develop Aug 12, 2021
@sphuber sphuber deleted the fix/4420/process-builder-instance-interference branch August 12, 2021 07:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unrelated builders interfere with each other
2 participants