https://dagster.io/ logo
#ask-ai
Title
# ask-ai
m

Martin Laurent

02/06/2024, 2:19 PM
getting this error on a simple op that should return an Output with a string value and metadata:
TypeError: Cannot handle objects of type <class 'str'>
s

Scout

02/06/2024, 2:19 PM
The error message you're encountering suggests that Dagster is having trouble handling an object of type
str
when it's expecting an
Output
object. This can happen if you're trying to return a plain string from an op instead of wrapping it in an
Output
object. According to the documentation, when you want to return a value from an op and attach metadata to it, you should use the
Output
object. Here's an example of how to correctly return an
Output
object with a string value and metadata:
Copy code
python from dagster import Output, op  @op def my_output_op() -> Output[str]:     return Output("some_value", metadata={"some_metadata": "a_value"})
In this example, the
Output
object is being used to return the string
"some_value"
from the op
my_output_op
, and it includes metadata with a key
"some_metadata"
and a value
"a_value"
. If you're encountering the
TypeError
, it's likely that your op is returning a string directly instead of using an
Output
object. Make sure that your op is structured similarly to the example above, wrapping the return value in an
Output
object and specifying any metadata you want to include. If you're already doing this and still encountering the error, there might be another issue at play. In that case, please ensure that your op's return type annotation matches the type of the
Output
object you're returning, and double-check that you're not accidentally returning a plain string or other object type that Dagster isn't expecting.
4 Views