airbytehq/PyAirbyte

is_interactive() throwing an exception inside an ASGI

Closed this issue · 3 comments

I'm trying to run PyAirbyte behind a simple REST API which would make PyAirbyte code being executed inside an ASGI application (FastAPI to start) however I am consistently getting the following exception upon server starting up with just an import of import airbyte as ab.

    from airbyte.secrets.base import SecretString 
  File "/Users/myworkspace/work/myapp/data-pipeline/.venv/lib/python3.11/site-packages/airbyte/secrets/__init__.py", line 6, in <module>
    from airbyte.secrets import (
  File "/Users/myworkspace/work/myapp/data-pipeline/.venv/lib/python3.11/site-packages/airbyte/secrets/config.py", line 43, in <module>
    _ = _get_secret_sources()
        ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/myworkspace/work/myapp/data-pipeline/.venv/lib/python3.11/site-packages/airbyte/secrets/config.py", line 36, in _get_secret_sources
    if meta.is_interactive():
       ^^^^^^^^^^^^^^^^^^^^^
  File "/Users/myworkspace/work/myapp/data-pipeline/.venv/lib/python3.11/site-packages/airbyte/_util/meta.py", line 65, in is_interactive
    return bool(sys.__stdin__.isatty() and sys.__stdout__.isatty())
                ^^^^^^^^^^^^^^^^^^^^^^
ValueError: I/O operation on closed file

Is this a simple fix of just wrapping this code in an exception handler? If so, happy to open a PR.

try:
        if is_colab() or is_jupyter():
            return True

        if is_ci():
            return False

        return sys.__stdin__.isatty() and sys.__stdout__.isatty()
    except ValueError:
        return False

@rshorser - Thanks for opening this issue and sharing the failure, and your proposed fix. I completely agree with you on the proposed fix. In the case that the check itself fails, then defaulting to the result of is_interactive() to false would make perfect sense.

We would welcome a PR if you are able to create one for this fix. 👍

cc @bindipankhudi for visibility

@aaronsteers awesome, thanks for the quick reply. PR open here to fix