-
Notifications
You must be signed in to change notification settings - Fork 37
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
Raise error for groups that decorate non-operation functions #544
Conversation
Codecov Report
@@ Coverage Diff @@
## master #544 +/- ##
==========================================
- Coverage 78.36% 78.27% -0.10%
==========================================
Files 31 31
Lines 3087 3088 +1
Branches 598 598
==========================================
- Hits 2419 2417 -2
- Misses 521 526 +5
+ Partials 147 145 -2
Continue to review full report at Codecov.
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I revised the error message text and pushed a change. I had a question about the __name__
attribute.
Also we should consider whether invalid FlowProject
definitions should raise a ValueError
or a RuntimeError
, I put a message in Slack about that and copied it below.
FlowProject definition errors: Should we prefer
RuntimeError
orValueError
? Current behavior:
ValueError
s:
- Attempting to put more than one
@FlowProject.operation
decorator on the same function- Attempting to define another operation with the same name as as existing operation
- Registering a condition function as an operation
- Registering an operation as a condition
- Defining a single function as an operation for two projects
A
andB
, whereB
inherits fromA
- Using
FlowProject.pre.after
with a function isn't an operation- Creating an operation with the same name as an existing group
- Creating a group with the same name as an existing operation
- (Proposed in this PR): Registering a group on a function that is not an operation
RuntimeError
s:
- Using
@cmd
before@with_job
- Using
@aggregator
and@with_job
on the same operation (in either order)
This code currently fails when used with custom operation names. from flow import FlowProject
class Project(FlowProject):
pass
group = Project.make_group("group")
@group
@Project.operation("custom_operation_name")
def print_job(job):
print(job)
if __name__ == "__main__":
Project().main() Raises error:
Edit: I thought for a while and experimented with some code but I don't see a solution for this. If we assume the function is registered as an operation first ( |
My suggestion on the corresponding issue here was also predicated on enforcing an ordering for the decorators. At the time I said that this might not be desirable, but I think we should consider requiring that the |
I don't think it's too much of an effort to add a check for the case which @bdice mentioned. The solution which immediately comes to my mind requires storing the |
@kidrahahjo @vyasr I think it is fine to require an order for the decorators. |
I think the path forward then is to require an order for the decorators and then just look up the names in |
I'm taking a look at this PR and will try to finalize it tonight. @b-butler said he and @kidrahahjo are planning to release 0.16 tomorrow. |
@b-butler @kidrahahjo I forgot to handle decorator ordering when I worked on this last night, and have retracted my approval. There is still some additional work needed for that, so I suggest that we bump this to a later version. 👍 |
@bdice sounds good. I will change the milestone for this PR and associated issue then. 😃 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good. A few more changes and this should be ready.
This could also be considered a breaking change, so what are thoughts on merging this without a deprecation cycle? The error message does give the fix which helps mitigate any pain in switching so I am fine with merging.
I'm going to look into the outstanding status error here and see if I can help resolve it so that we can get this merged. |
@bdice I don't think there's anything wrong here. If you look at the test project definition the old version of |
Yeah, I'm fine just merging this. To an extent this is almost like a bug fix, it's resolving some undesirable edge cases in behavior. |
@b-butler let me know if you're happy with the way that I addressed your comments, I had to make some adaptations to deal with inherited operations between projects and to avoid conflicts. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I have one suggestion and I will approve.
Co-authored-by: Brandon Butler <butlerbr@umich.edu>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
Description
Throw an error when a group decorates a non-operation function
Example
Motivation and Context
Fix #538
Types of Changes
1The change breaks (or has the potential to break) existing functionality.
Checklist:
If necessary: