Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

modal run/modal serve/modal deploy fail in Python 3.12 when python-dotenv's dotenv.load_dotenv() is called at module level #976

Open
zsiegel92 opened this issue Nov 15, 2024 · 0 comments

Comments

@zsiegel92
Copy link

This is a frustrating bug because I can't reproduce it in a minimal environment.

But in my application, if I load_dotenv() in a top-level I cannot modal X where X id deploy, run, serve. Note that I only experience this error with 3.12, never 3.11, and for a while I was modal deploying Python 3.12 apps from a local 3.11 interpreter.

Normally I wouldn't submit an issue for something I can't reproduce minimally and normally I wouldn't paste a long error log without doing more work but for me this is really opaque and it took me a while to even figure out that load_dotenv was causing the issue. I get these logs:

(venv3.12.5) ~/code/my_repository $ python -m modal serve --env etl my_app_folder/main.py
╭─ Error ──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╮
│ Non-thread-safe operation invoked on an event loop other than the current one                                                                                                                                                                                                │
╰──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────╯
Task was destroyed but it is pending!
source_traceback: Object created at (most recent call last):
  File "<frozen runpy>", line 198, in _run_module_as_main
  File "<frozen runpy>", line 88, in _run_code
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/modal/__main__.py", line 85, in <module>
    main()
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/modal/__main__.py", line 24, in main
    entrypoint_cli()
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/click/core.py", line 1157, in __call__
    return self.main(*args, **kwargs)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/typer/core.py", line 728, in main
    return _main(
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/typer/core.py", line 197, in _main
    rv = self.invoke(ctx)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/click/core.py", line 1688, in invoke
    return _process_result(sub_ctx.command.invoke(sub_ctx))
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/click/core.py", line 1434, in invoke
    return ctx.invoke(self.callback, **ctx.params)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/click/core.py", line 783, in invoke
    return __callback(*args, **kwargs)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/typer/main.py", line 707, in wrapper
    return callback(**use_params)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/modal/cli/run.py", line 328, in serve
    with serve_app(app, app_ref, environment_name=env):
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/synchronicity/synchronizer.py", line 593, in proxy_method
    return wrapped_method(instance, *args, **kwargs)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/synchronicity/combined_types.py", line 26, in __call__
    return self._func(*args, **kwargs)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/synchronicity/synchronizer.py", line 511, in f_wrapped
    return self._run_function_sync(res, f)
  File "/Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/synchronicity/synchronizer.py", line 312, in _run_function_sync
    coro_task = asyncio.ensure_future(coro, loop=loop)
  File "/Users/zsiegel/.pyenv/versions/3.12.5/lib/python3.12/asyncio/tasks.py", line 695, in ensure_future
    return loop.create_task(coro_or_future)
  File "/Users/zsiegel/.pyenv/versions/3.12.5/lib/python3.12/asyncio/base_events.py", line 458, in create_task
    task = tasks.Task(coro, loop=self, name=name, context=context)
task: <Task pending name='Task-2' coro=<Synchronizer._wrap_check_async_leakage.<locals>.coro_wrapped() done, defined at /Users/zsiegel/code/my_repository/venv3.12.5/lib/python3.12/site-packages/synchronicity/synchronizer.py:225> created at /Users/zsiegel/.pyenv/versions/3.12.5/lib/python3.12/asyncio/base_events.py:458>
sys:1: RuntimeWarning: coroutine 'wrap_coro_exception.<locals>.coro_wrapped' was never awaited
sys:1: RuntimeWarning: coroutine '_AsyncGeneratorContextManager.__aenter__' was never awaited

If you have to close this because it's incomplete please go ahead, but if anyone knows what this error is and how to avoid it maybe you can:

  • document what not to do (I still don't know what rule I was violating)
  • improve the error message
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant