Error when using Prefect 2.0: AttributeError: type object 'ORMInsert' has no attribute 'orm_pre_session_exec'

I am not able to get Prefect 2.0 up and running. I have tried it on Google Cloud Shell and Windows WSL2 and in both cases I get a similar error. This is on Google Cloud Shell with Prefect 2.0b2.

I try running this simple code from the tutorial:

from prefect import flow

@flow
def my_favorite_function():
    print("This function doesn't do much")
    return 42

state = my_favorite_function()

And then I get this error:

Traceback (most recent call last):
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/test.py", line 8, in <module>
    state = my_favorite_function()
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/flows.py", line 314, in __call__
    return enter_flow_run_engine_from_flow_call(self, parameters)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/engine.py", line 110, in enter_flow_run_engine_from_flow_call
    return anyio.run(begin_run)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/anyio/_core/_eventloop.py", line 56, in run
    return asynclib.run(func, *args, **backend_options)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 233, in run
    return native_run(wrapper(), debug=debug)
  File "/usr/lib/python3.9/asyncio/runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.9/asyncio/base_events.py", line 642, in run_until_complete
    return future.result()
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/anyio/_backends/_asyncio.py", line 228, in wrapper
    return await func(*args)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/client.py", line 80, in with_injected_client
    async with client_context as client:
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/client.py", line 1692, in __aenter__
    self._ephemeral_lifespan = await self._exit_stack.enter_async_context(
  File "/usr/lib/python3.9/contextlib.py", line 556, in enter_async_context
    result = await _cm_type.__aenter__(cm)
  File "/usr/lib/python3.9/contextlib.py", line 175, in __aenter__
    return await self.gen.__anext__()
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/client.py", line 146, in app_lifespan_context
    async with context:
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/asgi_lifespan/_manager.py", line 92, in __aenter__
    await self._exit_stack.aclose()
  File "/usr/lib/python3.9/contextlib.py", line 593, in aclose
    await self.__aexit__(None, None, None)
  File "/usr/lib/python3.9/contextlib.py", line 651, in __aexit__
    raise exc_details[1]
  File "/usr/lib/python3.9/contextlib.py", line 634, in __aexit__
    cb_suppress = await cb(*exc_details)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/asgi_lifespan/_concurrency/asyncio.py", line 80, in __aexit__
    await self.task
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/asgi_lifespan/_manager.py", line 90, in __aenter__
    await self.startup()
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/asgi_lifespan/_manager.py", line 36, in startup
    raise self._app_exception
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/asgi_lifespan/_concurrency/asyncio.py", line 63, in run_and_silence_cancelled
    await self.coroutine()
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/asgi_lifespan/_manager.py", line 64, in run_app
    await self.app(scope, self.receive, self.send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/fastapi/applications.py", line 261, in __call__
    await super().__call__(scope, receive, send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/applications.py", line 112, in __call__
    await self.middleware_stack(scope, receive, send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/middleware/errors.py", line 146, in __call__
    await self.app(scope, receive, send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/middleware/cors.py", line 76, in __call__
    await self.app(scope, receive, send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/exceptions.py", line 58, in __call__
    await self.app(scope, receive, send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
    raise e
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
    await self.app(scope, receive, send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/routing.py", line 645, in __call__
    await self.lifespan(scope, receive, send)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/routing.py", line 621, in lifespan
    async with self.lifespan_context(app):
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/routing.py", line 518, in __aenter__
    await self._router.startup()
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/starlette/routing.py", line 598, in startup
    await handler()
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/orion/api/server.py", line 233, in add_block_specifications
    await create_block_spec(
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/orion/database/dependencies.py", line 102, in async_wrapper
    return await fn(*args, **kwargs)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/prefect/orion/models/block_specs.py", line 42, in create_block_spec
    await session.execute(insert_stmt)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/sqlalchemy/ext/asyncio/session.py", line 212, in execute
    result = await greenlet_spawn(
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/sqlalchemy/util/_concurrency_py3k.py", line 123, in greenlet_spawn
    result = context.switch(*args, **kwargs)
  File "/home/benny/TooManySecrets/Georgia/Backend_flows/env/lib/python3.9/site-packages/sqlalchemy/orm/session.py", line 1640, in execute
    ) = compile_state_cls.orm_pre_session_exec(
AttributeError: type object 'ORMInsert' has no attribute 'orm_pre_session_exec'

Any suggestions on what I am doing wrong?

Do you get this error just after installing + starting Orion, and running this hello-world flow?

I will open an issue for it to check. Thanks for reporting this.

Could you perhaps try the same with Cloud 2.0? This way, you connect to a remote API. Here is how you can get started:

Thanks. Yes, so the error comes up when I run:

python hello-world.py

I will try the Prefect Cloud suggestion tonight.

1 Like

Thanks! I would appreciate it if you can try Cloud 2.0 for now. I created an issue you can follow here:

Thanks for flagging this.

Yes, it does work with Cloud 2.0. Thanks

1 Like