Closed hroi closed 1 year ago
Thanks for reporting this, @hroi!
I wasn't able to reproduce this running the same setup. When I use Homebrew-installed Python 3.11 on MacOS 13.1, then put my code in a file named test.py
and run python3 test.py
, I get the following:
16:28:34.539 | INFO | prefect.engine - Created flow run 'skinny-sidewinder' for flow 'my-favorite-function'
What is your favorite number?
16:28:34.596 | INFO | Flow run 'skinny-sidewinder' - Finished in state Completed()
42
Are you using a Python script to run your code like I did? Or are you running some other way, like in a notebook? It's not wrong if you're doing that. I only ask so I can help figure out why you're seeing this error.
I run the script using /usr/local/bin/python3.11 ./flow.py
I tried uninstalling numpy using brew uninstall numpy
. After uninstalling numpy it crashes in a new way:
08:56:23.936 | INFO | prefect.engine - Created flow run 'piquant-lyrebird' for flow 'my-favorite-function'
08:56:23.959 | ERROR | prefect.orion - Encountered exception in request:
Traceback (most recent call last):
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
raise exc
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 706, in __call__
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
response = await func(request)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/utilities/server.py", line 101, in handle_response_scoped_depends
response = await default_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 237, in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
return await dependant.call(**values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/api/block_schemas.py", line 137, in read_block_schema_by_checksum
block_schema = await models.block_schemas.read_block_schema_by_checksum(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/database/dependencies.py", line 117, in async_wrapper
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/models/block_schemas.py", line 729, in read_block_schema_by_checksum
sa.select(
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/_selectable_constructors.py", line 493, in select
return Select(*entities)
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/selectable.py", line 5160, in __init__
self._raw_columns = [
^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/selectable.py", line 5161, in <listcomp>
coercions.expect(
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 413, in expect
resolved = impl._literal_coercion(
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 652, in _literal_coercion
self._raise_for_expected(element, argname)
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 1143, in _raise_for_expected
return super()._raise_for_expected(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 711, in _raise_for_expected
super()._raise_for_expected(
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 536, in _raise_for_expected
raise exc.ArgumentError(msg, code=code) from err
sqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got [<class 'prefect.orion.database.orm_models.BaseORMConfiguration._create_orm_models.<locals>.BlockSchema'>, Column('name', String(), table=<block_schema_references>, nullable=False), Column('parent_block_schema_id', UUID(), ForeignKey('block_schema.id'), table=<block_schema_references>, nullable=False)]. Did you mean to say select(<class 'prefect.orion.database.orm_models.BaseORMConfiguration._create_orm_models.<locals>.BlockSchema'>, Column('name', String(), table=<block_schema_references>, nullable=False), Column('parent_block_schema_id', UUID(), ForeignKey('block_schema.id'), table=<block_schema_references>, nullable=False))?
08:56:23.964 | ERROR | Flow run 'piquant-lyrebird' - Crash detected! Execution was interrupted by an unexpected exception: sqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got [<class 'prefect.orion.database.orm_models.BaseORMConfiguration._create_orm_models.<locals>.BlockSchema'>, Column('name', String(), table=<block_schema_references>, nullable=False), Column('parent_block_schema_id', UUID(), ForeignKey('block_schema.id'), table=<block_schema_references>, nullable=False)]. Did you mean to say select(<class 'prefect.orion.database.orm_models.BaseORMConfiguration._create_orm_models.<locals>.BlockSchema'>, Column('name', String(), table=<block_schema_references>, nullable=False), Column('parent_block_schema_id', UUID(), ForeignKey('block_schema.id'), table=<block_schema_references>, nullable=False))?
Traceback (most recent call last):
File "/Users/hroi/code/python/prefect-play/./flow.py", line 8, in <module>
print(my_favorite_function())
^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/flows.py", line 456, in __call__
return enter_flow_run_engine_from_flow_call(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/engine.py", line 170, in enter_flow_run_engine_from_flow_call
return anyio.run(begin_run)
^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/_core/_eventloop.py", line 70, in run
return asynclib.run(func, *args, **backend_options)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 292, in run
return native_run(wrapper(), debug=debug)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 190, in run
return runner.run(main)
^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/runners.py", line 118, in run
return self._loop.run_until_complete(task)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/lib/python3.11/asyncio/base_events.py", line 653, in run_until_complete
return future.result()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/anyio/_backends/_asyncio.py", line 287, in wrapper
return await func(*args)
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/utilities.py", line 47, in with_injected_client
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/engine.py", line 243, in create_then_begin_flow_run
state = await begin_flow_run(
^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/engine.py", line 371, in begin_flow_run
flow_run_context.result_factory = await ResultFactory.from_flow(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/utilities.py", line 47, in with_injected_client
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/results.py", line 161, in from_flow
return await cls.default_factory(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/utilities.py", line 47, in with_injected_client
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/results.py", line 123, in default_factory
return await cls.from_settings(**kwargs, client=client)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/utilities.py", line 47, in with_injected_client
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/results.py", line 229, in from_settings
storage_block_id, storage_block = await cls.resolve_storage_block(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/results.py", line 257, in resolve_storage_block
or await storage_block._save(
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/utilities.py", line 47, in with_injected_client
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/blocks/core.py", line 833, in _save
await self.register_type_and_schema(client=client)
File "/usr/local/lib/python3.11/site-packages/prefect/client/utilities.py", line 47, in with_injected_client
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/blocks/core.py", line 787, in register_type_and_schema
block_schema = await client.read_block_schema_by_checksum(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/orion.py", line 1121, in read_block_schema_by_checksum
response = await self._client.get(url)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1757, in get
return await self.request(
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1533, in request
return await self.send(request, auth=auth, follow_redirects=follow_redirects)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/base.py", line 229, in send
response = await self._send_with_retry(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/client/base.py", line 187, in _send_with_retry
response = await request()
^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1620, in send
response = await self._send_handling_auth(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1648, in _send_handling_auth
response = await self._send_handling_redirects(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1685, in _send_handling_redirects
response = await self._send_single_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_client.py", line 1722, in _send_single_request
response = await transport.handle_async_request(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/httpx/_transports/asgi.py", line 162, in handle_async_request
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 271, in __call__
await super().__call__(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 118, in __call__
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__
raise exc
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/cors.py", line 84, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
raise exc
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 706, in __call__
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 443, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/fastapi/applications.py", line 271, in __call__
await super().__call__(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/applications.py", line 118, in __call__
await self.middleware_stack(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 184, in __call__
raise exc
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 79, in __call__
raise exc
File "/usr/local/lib/python3.11/site-packages/starlette/middleware/exceptions.py", line 68, in __call__
await self.app(scope, receive, sender)
File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 21, in __call__
raise e
File "/usr/local/lib/python3.11/site-packages/fastapi/middleware/asyncexitstack.py", line 18, in __call__
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 706, in __call__
await route.handle(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 276, in handle
await self.app(scope, receive, send)
File "/usr/local/lib/python3.11/site-packages/starlette/routing.py", line 66, in app
response = await func(request)
^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/utilities/server.py", line 101, in handle_response_scoped_depends
response = await default_handler(request)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 237, in app
raw_response = await run_endpoint_function(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/fastapi/routing.py", line 163, in run_endpoint_function
return await dependant.call(**values)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/api/block_schemas.py", line 137, in read_block_schema_by_checksum
block_schema = await models.block_schemas.read_block_schema_by_checksum(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/database/dependencies.py", line 117, in async_wrapper
return await fn(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/prefect/orion/models/block_schemas.py", line 729, in read_block_schema_by_checksum
sa.select(
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/_selectable_constructors.py", line 493, in select
return Select(*entities)
^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/selectable.py", line 5160, in __init__
self._raw_columns = [
^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/selectable.py", line 5161, in <listcomp>
coercions.expect(
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 413, in expect
resolved = impl._literal_coercion(
^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 652, in _literal_coercion
self._raise_for_expected(element, argname)
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 1143, in _raise_for_expected
return super()._raise_for_expected(
^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 711, in _raise_for_expected
super()._raise_for_expected(
File "/usr/local/lib/python3.11/site-packages/sqlalchemy/sql/coercions.py", line 536, in _raise_for_expected
raise exc.ArgumentError(msg, code=code) from err
sqlalchemy.exc.ArgumentError: Column expression, FROM clause, or other columns clause element expected, got [<class 'prefect.orion.database.orm_models.BaseORMConfiguration._create_orm_models.<locals>.BlockSchema'>, Column('name', String(), table=<block_schema_references>, nullable=False), Column('parent_block_schema_id', UUID(), ForeignKey('block_schema.id'), table=<block_schema_references>, nullable=False)]. Did you mean to say select(<class 'prefect.orion.database.orm_models.BaseORMConfiguration._create_orm_models.<locals>.BlockSchema'>, Column('name', String(), table=<block_schema_references>, nullable=False), Column('parent_block_schema_id', UUID(), ForeignKey('block_schema.id'), table=<block_schema_references>, nullable=False))?
@hroi can you share more details about your setup? We're not getting other reports of this and can't reproduce it. You'll need to give us a way to reproduce your Python environment.
This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment.
This issue was closed because it has been stale for 14 days with no activity. If this issue is important or you have more to add feel free to re-open it.
Just in case someone encounters the same issue again (as I just have), the reason seems to be somewhere deep in orjson, which is used within pydantic (a dependency of prefect) to create a json representation of the flow.
The following code snipped triggered the exact same error as I was also getting when following the prefect tutorial:
import orjson
import decimal
def testDefault(obj):
if isinstance(obj, decimal.Decimal):
return str(obj)
# Works:
orjson.dumps({"set":{1, 2}}, default=testDefault)
orjson.dumps({"set":{1, 2}}, default=testDefault, option=orjson.OPT_NON_STR_KEYS)
# Here comes the error so
orjson.dumps({"set":{1, 2}}, default=testDefault, option=orjson.OPT_NON_STR_KEYS | orjson.OPT_SERIALIZE_NUMPY)
I proceeded with installing numpy through pip and verified the orjson snipped and the prefect flow worked, afterwards I uninstalled it and it was still working... Strange but just wanted to let others know on how to get around this issue
Python 3.11.7 MacOS 14.2.1 orjson 3.9.15
First check
Bug summary
Running the very first basic flow from the tutorial crashes with
TypeError: Type is not JSON serializable: set
Reproduction
Error
Versions
Additional context
macOS 13.1 python 3.11 via homebrew
Flow copied from https://docs.prefect.io/tutorials/first-steps/