https://prefect.io logo
Title
e

Emerson Franks

09/07/2022, 11:40 PM
Hello, I recently upgraded my package from 2.2.0 -> 2.3.2. When attempting to run a deployment build command that worked on 2.2.0, I am now getting the error in my following reply. If I go back to 2.2.0 things work fine. My flow is just the health_check that is in documentation. Did I miss a step when upgrading the package?
👀 1
1
Error:
$ prefect deployment build health_check.py:health_check -n health_check -t kubernetes -i kubernetes-job -sb azure/logblock -o health_check_20220907 --override image=<http://recroomdataplatmdev.azurecr.io/orion-adlfs:latestfor|recroomdataplatmdev.azurecr.io/orion-adlfs:latestfor> --override namespace=aug2022 --interval=300 -q kubernetes
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 "C:\repos\RecNetDP.Orchestration\flows\health_check.py", line 5, in <module>
    az_block=Azure.load("logblock")
  File "C:\Python310\lib\site-packages\prefect\utilities\asyncutils.py", line 198, in wrapper
    raise RuntimeError(
RuntimeError: A 'sync_compatible' method was called from a context that was previously async but is now sync. The sync call must be changed to run in a worker thread to support sending the coroutine for 'load' to the main thread.

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

Traceback (most recent call last):
  File "C:\Python310\lib\site-packages\prefect\cli\_utilities.py", line 41, in wrapper
    return fn(*args, **kwargs)
  File "C:\Python310\lib\site-packages\prefect\utilities\asyncutils.py", line 212, in wrapper
    return run_async_in_new_loop(async_fn, *args, **kwargs)
  File "C:\Python310\lib\site-packages\prefect\utilities\asyncutils.py", line 141, in run_async_in_new_loop
    return anyio.run(partial(__fn, *args, **kwargs))
  File "C:\Python310\lib\site-packages\anyio\_core\_eventloop.py", line 70, in run
    return asynclib.run(func, *args, **backend_options)
  File "C:\Python310\lib\site-packages\anyio\_backends\_asyncio.py", line 292, in run
    return native_run(wrapper(), debug=debug)
  File "C:\Python310\lib\asyncio\runners.py", line 44, in run
    return loop.run_until_complete(main)
  File "C:\Python310\lib\asyncio\base_events.py", line 646, in run_until_complete
    return future.result()
  File "C:\Python310\lib\site-packages\anyio\_backends\_asyncio.py", line 287, in wrapper
    return await func(*args)
  File "C:\Python310\lib\site-packages\prefect\cli\deployment.py", line 494, in build
    flow = prefect.utilities.importtools.import_object(entrypoint)
  File "C:\Python310\lib\site-packages\prefect\utilities\importtools.py", line 193, in import_object
    module = load_script_as_module(script_path)
  File "C:\Python310\lib\site-packages\prefect\utilities\importtools.py", line 156, in load_script_as_module
    raise ScriptError(user_exc=exc, path=path) from exc
prefect.exceptions.ScriptError: Script at 'health_check.py' encountered an exception
An exception occurred.
Flow:
import prefect
from prefect import task, flow, get_run_logger
from prefect.filesystems import Azure

az_block=Azure.load("logblock")

@task
def log_platform_info():
    import platform
    import sys
    from prefect.orion.api.server import ORION_API_VERSION

    logger=get_run_logger()
    <http://logger.info|logger.info>(f"Host's network name: {platform.node()}")
    <http://logger.info|logger.info>(f"Python version: {platform.python_version()}")
    <http://logger.info|logger.info>(f"Platform information (instance type): {platform.platform()}")
    <http://logger.info|logger.info>(f"OS/Arch: {sys.platform} {platform.machine()}")
    <http://logger.info|logger.info>(f"Prefect Version: {prefect.__version__}")
    <http://logger.info|logger.info>(f"Prefect API Version: {ORION_API_VERSION}")

@flow
def health_check():
    log_platform_info()

if __name__ == "__main__":
    health_check()
Command:
prefect deployment build health_check.py:health_check -n health_check -t kubernetes -i kubernetes-job -sb azure/logblock -o health_check_20220907 --override image=${acr} --override namespace=aug2022 --interval=300 -q kubernetes
So apparently it was the Azure.load call causing the issue, removing that gets rid of the exception. Should I not be making this call in 2.3+?
k

Keith

09/09/2022, 8:28 PM
I am having the same issue with GCS, it looks like there is a ticket open but not sure on the resolution: https://github.com/PrefectHQ/prefect/issues/6677
I fixed it by moving the GCS block inside the Flow
🙌 1
e

Emerson Franks

09/14/2022, 7:54 PM
Thanks @Keith! That fixes the Azure version as well!
👍 2
s

Saman

09/21/2022, 11:55 AM
So basically, don’t you need the part az_block = Azure.load(“blockName”) in the code if you have it in the prefect build command? What if I want all my build parameters part of the code and nothing in the cli line?