Arun Kumar
09/11/2021, 1:59 AMchris
09/11/2021, 2:13 AM@resource
@contextmanager
def my_cm_resource(_):
yield "foo"
Can also do try/finally syntaxArun Kumar
09/11/2021, 2:18 AMsolid1
, but errors out while executing solid2
Am I missing something here?
class ServiceClient:
def __init__(self):
self.msg = "Foo"
@resource
@contextmanager
def service_resource(_):
yield ServiceClient()
@solid(required_resource_keys={"service_client"})
def solid1(context):
with context.resources.service_client as service:
<http://context.log.info|context.log.info>(service.msg)
@solid(required_resource_keys={"service_client"})
def solid2(context):
with context.resources.service_client as service:
<http://context.log.info|context.log.info>(service.msg)
@pipeline(mode_defs=[ModeDefinition(resource_defs={"service_client": service_resource})])
def hello_pipeline():
solid1()
solid2()
AttributeError: args
File "/Users/abalasubramani/.pyenv/versions/3.8.0/lib/python3.8/site-packages/dagster/core/execution/plan/utils.py", line 44, in solid_execution_error_boundary
yield
File "/Users/abalasubramani/.pyenv/versions/3.8.0/lib/python3.8/site-packages/dagster/utils/__init__.py", line 383, in iterate_with_context
next_output = next(iterator)
File "/Users/abalasubramani/.pyenv/versions/3.8.0/lib/python3.8/site-packages/dagster/core/execution/plan/compute_generator.py", line 65, in _coerce_solid_compute_fn_to_iterator
result = fn(context, **kwargs) if context_arg_provided else fn(**kwargs)
File "pipeline.py", line 24, in solid2
with context.resources.service_client as service:
File "/Users/abalasubramani/.pyenv/versions/3.8.0/lib/python3.8/contextlib.py", line 111, in __enter__
del self.args, self.kwds, self.func
chris
09/12/2021, 1:02 PMArun Kumar
09/12/2021, 10:18 PMAttributeError: '_GeneratorContextManager' object has no attribute 'msg'
File "/Users/abalasubramani/.pyenv/versions/3.8.0/lib/python3.8/site-packages/dagster/core/execution/plan/utils.py", line 44, in solid_execution_error_boundary
yield
File "/Users/abalasubramani/.pyenv/versions/3.8.0/lib/python3.8/site-packages/dagster/utils/__init__.py", line 383, in iterate_with_context
next_output = next(iterator)
File "/Users/abalasubramani/.pyenv/versions/3.8.0/lib/python3.8/site-packages/dagster/core/execution/plan/compute_generator.py", line 65, in _coerce_solid_compute_fn_to_iterator
result = fn(context, **kwargs) if context_arg_provided else fn(**kwargs)
File "pipeline.py", line 23, in solid2
<http://context.log.info|context.log.info>(context.resources.service_client.msg)
class ServiceClient:
def __init__(self):
self.msg = "Foo"
@resource
@contextmanager
def service_resource(_):
yield ServiceClient()
@solid(required_resource_keys={"service_client"})
def solid1(context):
<http://context.log.info|context.log.info>(context.resources.service_client.msg)
@solid(required_resource_keys={"service_client"})
def solid2(context):
<http://context.log.info|context.log.info>(context.resources.service_client.msg)
@pipeline(mode_defs=[ModeDefinition(resource_defs={"service_client": service_resource})])
def hello_pipeline():
solid1()
solid2()
chris
09/13/2021, 2:06 AMArun Kumar
09/13/2021, 6:35 AMchris
09/22/2021, 4:55 AMArun Kumar
09/22/2021, 5:38 AMchris
09/25/2021, 1:04 AMArun Kumar
09/25/2021, 9:53 AMchris
10/26/2021, 4:21 AMArun Kumar
10/26/2021, 4:23 AMchris
10/26/2021, 4:49 AMfrom contextlib import contextmanager
from dagster import resource
@resource
@contextmanager
def my_resource():
try:
yield ...
finally:
...
Arun Kumar
10/28/2021, 10:23 PMchris
10/28/2021, 10:23 PM