Temporal + Selenium non-deterministic error Python SDK

Hi, I am getting this kind of exception while trying to use Selenium inside activity:

temporalio.worker.workflow_sandbox._restrictions.RestrictedWorkflowAccessError: Cannot access http.client.IncompleteRead.__mro_entries__ from inside a workflow.

My activity func looks like this:

@activity.defn
async def click_button(inpt: SomeInput):
    options = webdriver.ChromeOptions()
    options.add_argument('--ignore-ssl-errors=yes')
    options.add_argument('--ignore-certificate-errors')
    driver = webdriver.Remote(
        command_executor='http://localhost:4444/wd/hub',
        options=options
    )
    driver.maximize_window()
    # navigate to browserstack.com
    driver.get("https://github.com/SeleniumHQ/docker-selenium")

    try:
        element = WebDriverWait(driver, delay).until(
            EC.presence_of_element_located((By.CSS_SELECTOR, "a[class='btn ml-2']")))
        print("Page is ready!")
    except TimeoutException:
        print("Loading took too much time!")

    element.click()

@workflow.defn
class TestWorkflow:
    @workflow.run
    async def run(self, inp: str) -> str:
        return await workflow.execute_activity(
            click_button, SomeInput("Pew", inp), schedule_to_close_timeout=timedelta(
                seconds=5)
        )

async def main():
    # Create client connected to server at the given address
    client = await Client.connect("localhost:7233")
    # Execute a workflow

    # Run the worker
    async with Worker(
        client,
        task_queue="my-task-queue",
        workflows=[TestWorkflow],
        activities=[click_button],
    ):

        await client.execute_workflow(
            TestWorkflow.run,
            "Ivan",
            id="my-workflow-id",
            task_queue="my-task-queue",
        )


if __name__ == "__main__":
    asyncio.run(main())

I assume it happens that Temporal validator found non-deterministic stuff inside Selenium.
Is there some workaround with Python SDK that can fix it?

This is a known issue with our sandbox. We recommend putting workflows in different files than other code and passing through the other modules when importing in the workflow file.

We will by updating the docs/samples to clarify this soon.

1 Like