Hi! I have been having trouble connecting to flow_...
# ask-community
s
Hi! I have been having trouble connecting to flow_client through dagster: getting the following error :
Copy code
Error loading core_extract. Try reloading the code location after resolving the issue.
AttributeError: __enter__
  File "/usr/local/lib/python3.10/site-packages/dagster/_grpc/server.py", line 267, in __init__
    self._loaded_repositories: Optional[LoadedRepositories] = LoadedRepositories(
  File "/usr/local/lib/python3.10/site-packages/dagster/_grpc/server.py", line 116, in __init__
    loadable_targets = get_loadable_targets(
  File "/usr/local/lib/python3.10/site-packages/dagster/_grpc/utils.py", line 37, in get_loadable_targets
    else loadable_targets_from_python_file(python_file, working_directory)
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/workspace/autodiscovery.py", line 27, in loadable_targets_from_python_file
    loaded_module = load_python_file(python_file, working_directory)
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/code_pointer.py", line 86, in load_python_file
    return import_module_from_path(module_name, python_file)
  File "/usr/local/lib/python3.10/site-packages/dagster/_seven/__init__.py", line 49, in import_module_from_path
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 883, in exec_module
  File "<frozen importlib._bootstrap>", line 241, in _call_with_frames_removed
  File "/scripts/pipelines/core/extract/__init__.py", line 8, in <module>
    from pipelines.core.extract.assets.chain import factory_outputs as chain_factory_outputs
  File "/scripts/pipelines/core/extract/__init__.py", line 8, in <module>
    from pipelines.core.extract.assets.chain import factory_outputs as chain_factory_outputs
  File "/scripts/pipelines/core/extract/assets/chain/__init__.py", line 1, in <module>
    from .chain import factory_outputs as chain_factory_outputs
  File "/scripts/pipelines/core/extract/assets/chain/chain.py", line 57, in <module>
    end_block               = get_current_block() - block_partition_size,
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/definitions/assets.py", line 245, in __call__
    return solid_def(*args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/definitions/op_definition.py", line 439, in __call__
    return op_invocation_result(self, None, *args, **kwargs)
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/definitions/solid_invocation.py", line 60, in op_invocation_result
    result = invoke_compute_fn(
  File "/usr/local/lib/python3.10/site-packages/dagster/_core/execution/plan/compute_generator.py", line 115, in invoke_compute_fn
    return fn(context, **args_to_pass) if context_arg_provided else fn(**args_to_pass)
  File "/scripts/pipelines/core/extract/assets/chain/chain.py", line 33, in get_current_block
    with flow_client( host="<http://access.mainnet.nodes.onflow.org|access.mainnet.nodes.onflow.org>", port="9000") as client:
a
it looks like you are invoking an
asset
at import time which you probably dont want, notable stack trace line:
Copy code
File "/scripts/pipelines/core/extract/assets/chain/chain.py", line 57, in <module>
    end_block               = get_current_block() -
s
What could be the solution? i want to run get_current_block as an async func.
a
it appears that you are doing this computation at module scope as opposed to within a function . Moving it to be within a function would resolve if im interpreting this stack trace correctly
s
but the code worked fine before adding the following to get_latest_block function , previously it was return 15
Copy code
with flow_client( host="<http://access.mainnet.nodes.onflow.org|access.mainnet.nodes.onflow.org>", port="9000") as client:
    block = client.get_latest_block(is_sealed = True)
return block.height