fix: handle ServiceConflictError when reusing Actor across sequential context#804
fix: handle ServiceConflictError when reusing Actor across sequential context#804Mantisus wants to merge 3 commits intoapify:masterfrom
ServiceConflictError when reusing Actor across sequential context#804Conversation
There was a problem hiding this comment.
Pull request overview
This PR fixes ServiceConflictError when reusing Actor across sequential async context manager blocks. The issue occurred when mixing Actor (singleton proxy) and Actor() (new instances) in sequential contexts, as new instances would try to register services in the global service_locator that were already set by previous instances.
Changes:
- Added error handling in
event_managerproperty to catchServiceConflictErrorand reuse existing event manager from service_locator - Added parametrized test covering all four combinations of Actor/Actor() usage in sequential contexts
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
src/apify/_actor.py |
Wraps service_locator.set_event_manager() in try/except to handle ServiceConflictError and reuse existing event manager |
tests/unit/actor/test_actor_lifecycle.py |
Adds parametrized test for all Actor/Actor() combinations in sequential contexts |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Pijukatel
left a comment
There was a problem hiding this comment.
I am not so sure about the whole issue. I am afraid that allowing this implicitly leads to more edge cases. I would rather be explicit about such use case. Why not solve the actual issue (problem with example-code-runner-py running Actor() twice due to its unique use case)
apify/crawlee-python#1759
and
https://github.com/apify/example-code-runner-py/compare/master...reset-service-locator-if-custom-actor
|
Perhaps @vlada knows of some additional use cases so that we can better shape the expected behavior. I followed the general pattern for resources in |
Now imagine that somebody copies a snippet with repeated |
Do we have such a snippet somewhere? As far as I know, we do not advertise this usage anywhere, or? |
Description
ServiceConflictErrorwhen reusingActoracross sequential contextIssues
ServiceConflictError#678Testing