-
Notifications
You must be signed in to change notification settings - Fork 15
fix: Unify Actor context manager with init & exit methods #600
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
base: master
Are you sure you want to change the base?
Conversation
fcec3b9
to
3dacd65
Compare
Am not sure about this. What about this scenario?
This used to work before, but now it will try to call |
IMO that scenario is a misuse. You've got 2 approaches and you should choose one of them. Not combining them. |
People can use Can we keep a flag to know the exit method was already called, and skip the duplicated logic that would be otherwise produced by the context manager? |
I added one test. We can decide whether it is an allowed use case that should be supported or a misuse. |
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.
Judging by https://github.com/apify/apify-sdk-python/pull/600/files#diff-807ba3710b8cdf01f23374c98d85a91075d4b602c8c4a3b46ddb64696b16987d I suppose the point raised by @Pijukatel has been resolved?
If you mean this:
Then yes, this is a valid scenario (we have the |
run_result = await run_actor(actor) | ||
|
||
assert run_result.exit_code == 91 | ||
assert run_result.exit_code == ActorExitCodes.ERROR_USER_FUNCTION_THREW.value |
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 usually prefer "inlining" the constants to avoid tautological tests. Not a hill to die on in this case, just saying
Description
To align the behavior between the two possible approaches of using an Actor - as a context manager or by explicitly calling
init
/exit
/fail
- the following changes were implemented:exit_code
,status_message
,event_listeners_timeout
,cleanup_timeout
) were added to theActor.__init__
as well.exit_code
andstatus_message
are now public properties with setters, allowing them to be updated within a context manager block in response to error conditions.__aenter__
frominit
and__aexit__
fromexit
was reversed, ensuring fewer inconsistencies for future changes (since__aenter__
and__aexit__
have a fixed number of arguments).Other changes:
Issues
Testing