Skip to content

Commit

Permalink
Solid error message migration (#6883)
Browse files Browse the repository at this point in the history
* Fix nothing inputs error message away from using solid

* Clean up docstring away from using solid

* Add word to error message, fix tests
  • Loading branch information
dpeng817 committed Mar 3, 2022
1 parent f8319ea commit e3e2143
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ def resolve_checked_solid_fn_inputs(
Returns the resolved set of InputDefinitions.
Args:
decorator_name (str): Name of the decorator that is wrapping the solid function.
decorator_name (str): Name of the decorator that is wrapping the op/solid function.
fn_name (str): Name of the decorated function.
compute_fn (DecoratedSolidFunction): The decorated function, wrapped in the
DecoratedSolidFunction wrapper.
Expand Down Expand Up @@ -379,14 +379,18 @@ def resolve_checked_solid_fn_inputs(
for input_def in explicit_input_defs:
if input_def.name in inferred_props:
# combine any information missing on the explicit def that can be inferred
input_defs.append(input_def.combine_with_inferred(inferred_props[input_def.name]))
input_defs.append(
input_def.combine_with_inferred(
inferred_props[input_def.name], decorator_name=decorator_name
)
)
else:
# pass through those that don't have any inference info, such as Nothing type inputs
input_defs.append(input_def)

# build defs from the inferred props for those without explicit entries
input_defs.extend(
InputDefinition.create_from_inferred(inferred)
InputDefinition.create_from_inferred(inferred, decorator_name=decorator_name)
for inferred in inferred_props.values()
if inferred.name in inputs_to_infer
)
Expand Down
16 changes: 10 additions & 6 deletions python_modules/dagster/dagster/core/definitions/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,15 +224,19 @@ def mapping_to(self, solid_name, input_name, fan_in_index=None):
return InputMapping(self, maps_to)

@staticmethod
def create_from_inferred(inferred: InferredInputProps) -> "InputDefinition":
def create_from_inferred(
inferred: InferredInputProps, decorator_name: str
) -> "InputDefinition":
return InputDefinition(
name=inferred.name,
dagster_type=_checked_inferred_type(inferred),
dagster_type=_checked_inferred_type(inferred, decorator_name),
description=inferred.description,
default_value=inferred.default_value,
)

def combine_with_inferred(self, inferred: InferredInputProps) -> "InputDefinition":
def combine_with_inferred(
self, inferred: InferredInputProps, decorator_name: str
) -> "InputDefinition":
"""
Return a new InputDefinition that merges this ones properties with those inferred from type signature.
This can update: dagster_type, description, and default_value if they are not set.
Expand All @@ -245,7 +249,7 @@ def combine_with_inferred(self, inferred: InferredInputProps) -> "InputDefinitio

dagster_type = self._dagster_type
if self._type_not_set:
dagster_type = _checked_inferred_type(inferred)
dagster_type = _checked_inferred_type(inferred, decorator_name=decorator_name)

description = self._description
if description is None and inferred.description is not None:
Expand All @@ -267,7 +271,7 @@ def combine_with_inferred(self, inferred: InferredInputProps) -> "InputDefinitio
)


def _checked_inferred_type(inferred: InferredInputProps) -> DagsterType:
def _checked_inferred_type(inferred: InferredInputProps, decorator_name: str) -> DagsterType:
try:
resolved_type = resolve_dagster_type(inferred.annotation)
except DagsterError as e:
Expand All @@ -281,7 +285,7 @@ def _checked_inferred_type(inferred: InferredInputProps) -> DagsterType:
raise DagsterInvalidDefinitionError(
f"Input parameter {inferred.name} is annotated with {resolved_type.display_name} "
"which is a type that represents passing no data. This type must be used "
"via InputDefinition and no parameter should be included in the solid function."
f"via InputDefinition and no parameter should be included in the {decorator_name} decorated function."
)
return resolved_type

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,7 @@ def _bad(_, _previous_steps_complete):

with pytest.raises(
DagsterInvalidDefinitionError,
match="must be used via InputDefinition and no parameter should be included in the solid function",
match="must be used via InputDefinition and no parameter should be included in the @solid decorated function",
):

@solid
Expand Down

0 comments on commit e3e2143

Please sign in to comment.