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

prefect deploy script loading with complex callback hooks raising ScriptErrors #15942

Open
soamicharan opened this issue Nov 7, 2024 · 0 comments
Labels
bug Something isn't working

Comments

@soamicharan
Copy link
Contributor

Bug summary

I have a simple flow code which look like this

from prefect import flow
from unknown_module import unknown_import

def test_callback(params):
    print(params)
    print(unknown_import)
    def wrapper(*args, **kwargs):
        pass

    return wrapper


@flow(name="test_flow", on_running=[test_callback("hello")])
def test_flow():
    pass

I have a deployment yaml file

deployments:
  - name: test-deployment
    entrypoint: test_flow.py:test_flow
    work_pool:
      name: process-pool

Now when I run prefect --no-prompt deploy --all it raises following error

hello
hello
Traceback (most recent call last):
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/home/soami/test_flow.py", line 2, in <module>
    from unknown_module import unknown_import
ModuleNotFoundError: No module named 'unknown_module'

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/cli/_utilities.py", line 42, in wrapper
    return fn(*args, **kwargs)
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/utilities/asyncutils.py", line 311, in coroutine_wrapper
    return call()
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 432, in __call__
    return self.result()
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 318, in result
    return self.future.result(timeout=timeout)
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 179, in result
    return self.__get_result()
  File "/usr/lib/python3.10/concurrent/futures/_base.py", line 403, in __get_result
    raise self._exception
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/_internal/concurrency/calls.py", line 389, in _run_async
    result = await coro
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/cli/deploy.py", line 429, in deploy
    await _run_single_deploy(
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/client/utilities.py", line 100, in with_injected_client
    return await fn(*args, **kwargs)
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/cli/deploy.py", line 484, in _run_single_deploy
    flow = load_flow_from_entrypoint(deploy_config["entrypoint"])
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/flows.py", line 1684, in load_flow_from_entrypoint
    flow = import_object(entrypoint)
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/utilities/importtools.py", line 205, in import_object
    module = load_script_as_module(script_path)
  File "/home/soami/.local/lib/python3.10/site-packages/prefect/utilities/importtools.py", line 168, in load_script_as_module
    raise ScriptError(user_exc=exc, path=path) from exc
prefect.exceptions.ScriptError: Script at 'test_flow.py' encountered an exception: ModuleNotFoundError("No module named 'unknown_module'"

Version info

Version:             3.1.0
API version:         0.8.4
Python version:      3.10.12
Git commit:          a83ba39b
Built:               Thu, Oct 31, 2024 12:43 PM
OS/Arch:             linux/x86_64
Profile:             default
Server type:         unconfigured
Pydantic version:    2.8.2

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant