PrefectHQ / prefect

Prefect is a workflow orchestration framework for building resilient data pipelines in Python.
https://prefect.io
Apache License 2.0
16.4k stars 1.59k forks source link

Cannot pass unserializable-as-JSON objects with cyclical references to flows #8440

Open jggatter opened 1 year ago

jggatter commented 1 year ago

First check

Bug summary

Hello!

Thanks! James

Reproduction

from prefect import flow
import scanpy as sc

@flow(validate_parameters=False)
def process_adata(adata: sc.AnnData) -> sc.AnnData:
    return adata

adata = sc.datasets.pbmc68k_reduced()
process_adata(adata)

Error

Fatal Python error: Cannot recover from stack overflow.
Python runtime state: initialized

Thread 0x00007f295977f640 (most recent call first):
  File "/usr/local/lib/python3.8/concurrent/futures/thread.py", line 78 in _worker
  File "/usr/local/lib/python3.8/threading.py", line 870 in run
  File "/usr/local/lib/python3.8/threading.py", line 932 in _bootstrap_inner
  File "/usr/local/lib/python3.8/threading.py", line 890 in _bootstrap

Current thread 0x00007f29a2a76740 (most recent call first):
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/dtypes/generic.py", line 41 in _check
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/dtypes/generic.py", line 47 in _instancecheck
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/construction.py", line 444 in extract_array
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/arrays/_mixins.py", line 296 in __getitem__
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/internals/blocks.py", line 1832 in getitem_block_index
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/generic.py", line 4105 in _slice
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 1638 in _get_slice_axis
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 1602 in _getitem_axis
  File "/home/ubuntu/.local/lib/python3.8/site-packages/pandas/core/indexing.py", line 1073 in __getitem__
  File "/home/ubuntu/.local/lib/python3.8/site-packages/anndata/_core/anndata.py", line 336 in _init_as_view
  File "/home/ubuntu/.local/lib/python3.8/site-packages/anndata/_core/anndata.py", line 289 in __init__
  File "/home/ubuntu/.local/lib/python3.8/site-packages/anndata/_core/anndata.py", line 1114 in __getitem__
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 152 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 161 in jsonable_encoder
  File "/home/ubuntu/.local/lib/python3.8/site-packages/fastapi/encoders.py", line 117 in jsonable_encoder
  ...
Aborted (core dumped)

Versions

2.7.12, 2.7.9

Additional context

I also brought this up on Slack when I first encountered the issue. We were unable to determine a solution at that time but I appreciate the great support that Zanie offered!

jggatter commented 1 year ago

Bumping

zanieb commented 1 year ago

@jggatter please only post on issues if there is more information to share

github-actions[bot] commented 1 year ago

This issue is stale because it has been open 30 days with no activity. To keep this issue open remove stale label or comment.

jggatter commented 1 year ago

Commenting to remove stale label

CaioLC commented 11 months ago

Hi guys, I have a similar RecursiveError problem RecursionError: maximum recursion depth exceeded while calling a Python object, but with SQLAlchemy parameters passed into a flow.

Same as @jggatter, I have also checked for any discussions in Pydantic repository (https://github.com/pydantic/pydantic/issues/659), but it feels to me it is a low priority or out of scope problem for them.

As the recursive calls are (possibly?) due to prefect's pydantic / fastapi dependencies, I expected that setting flow validate_parameters=False would fix the issue. I also confirmed this behaviour is specific to flow.

How to reproduce the RecursiveError (I am using python 3.10 + prefect 2.14.3 on a W10 machine):

"""Sandbox for creating DAGs with prefect."""
from prefect import flow
from sqlalchemy import (
    Column,
    Integer,
    String,
)
from sqlalchemy.orm import declarative_base

Base = declarative_base()

class MockupTable(Base):
    """Equities table."""

    __tablename__ = "mockup"
    _id = Column("id", Integer(), primary_key=True, autoincrement=True)
    first_col = Column("first_col", String(), nullable=False)
    second_col = Column("second_col", String(), nullable=False)

if __name__ == "__main__":
    @flow(validate_parameters=False)
    def uniq(uni: Column):
        print(uni.name)
    uniq(MockupTable.first_col)

Changing flow to task I get the expected behaviour:


if __name__ == "__main__":
    @task
    def uniq(uni: Column):
        print(uni.name)

    @flow
    def my_flow():
        uniq(MockupTable.first_col)

    my_flow() # prints "first_col"

I've decided to post in this issue as my case seems similar enough. But let me know if I should open a specific issue.