fix(rnd): avoid duplicating name on input/output pin for blocks (#7979)

pull/7975/head^2
Zamil Majdy 2024-09-05 05:54:02 -05:00 committed by GitHub
parent 8ec015ba72
commit 70fab8711a
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 22 additions and 16 deletions

View File

@ -54,6 +54,15 @@ for cls in all_subclasses(Block):
if block.id in AVAILABLE_BLOCKS:
raise ValueError(f"Block ID {block.name} error: {block.id} is already in use")
# Prevent duplicate field name in input_schema and output_schema
duplicate_field_names = set(block.input_schema.__fields__.keys()) & set(
block.output_schema.__fields__.keys()
)
if duplicate_field_names:
raise ValueError(
f"{block.name} has duplicate field names in input_schema and output_schema: {duplicate_field_names}"
)
for field in block.input_schema.__fields__.values():
if field.annotation is bool and field.default not in (True, False):
raise ValueError(f"{block.name} has a boolean field with no default value")

View File

@ -140,7 +140,7 @@ class InputOutputBlockInput(BlockSchema, Generic[T]):
class InputOutputBlockOutput(BlockSchema, Generic[T]):
value: T = Field(description="The value passed as input/output.")
result: T = Field(description="The value passed as input/output.")
class InputOutputBlockBase(Block, ABC, Generic[T]):
@ -162,8 +162,8 @@ class InputOutputBlockBase(Block, ABC, Generic[T]):
{"value": MockObject(value="!!", key="key"), "name": "input_2"},
],
test_output=[
("value", {"apple": 1, "banana": 2, "cherry": 3}),
("value", MockObject(value="!!", key="key")),
("result", {"apple": 1, "banana": 2, "cherry": 3}),
("result", MockObject(value="!!", key="key")),
],
static_output=True,
*args,
@ -171,7 +171,7 @@ class InputOutputBlockBase(Block, ABC, Generic[T]):
)
def run(self, input_data: InputOutputBlockInput[T]) -> BlockOutput:
yield "value", input_data.value
yield "result", input_data.value
class InputBlock(InputOutputBlockBase[Any]):

View File

@ -57,7 +57,6 @@ class PublishToMediumBlock(Block):
class Output(BlockSchema):
post_id: str = SchemaField(description="The ID of the created Medium post")
post_url: str = SchemaField(description="The URL of the created Medium post")
author_id: str = SchemaField(description="The Medium user ID of the author")
published_at: int = SchemaField(
description="The timestamp when the post was published"
)
@ -85,7 +84,6 @@ class PublishToMediumBlock(Block):
test_output=[
("post_id", "e6f36a"),
("post_url", "https://medium.com/@username/test-post-e6f36a"),
("author_id", "1234567890abcdef"),
("published_at", 1626282600),
],
test_mock={
@ -156,7 +154,6 @@ class PublishToMediumBlock(Block):
if "data" in response:
yield "post_id", response["data"]["id"]
yield "post_url", response["data"]["url"]
yield "author_id", response["data"]["authorId"]
yield "published_at", response["data"]["publishedAt"]
else:
error_message = response.get("errors", [{}])[0].get(

View File

@ -103,14 +103,14 @@ class GetCurrentDateAndTimeBlock(Block):
class CountdownTimerBlock(Block):
class Input(BlockSchema):
message: Any = "timer finished"
input_message: Any = "timer finished"
seconds: Union[int, str] = 0
minutes: Union[int, str] = 0
hours: Union[int, str] = 0
days: Union[int, str] = 0
class Output(BlockSchema):
message: str
output_message: str
def __init__(self):
super().__init__(
@ -121,11 +121,11 @@ class CountdownTimerBlock(Block):
output_schema=CountdownTimerBlock.Output,
test_input=[
{"seconds": 1},
{"message": "Custom message"},
{"input_message": "Custom message"},
],
test_output=[
("message", "timer finished"),
("message", "Custom message"),
("output_message", "timer finished"),
("output_message", "Custom message"),
],
)
@ -139,4 +139,4 @@ class CountdownTimerBlock(Block):
total_seconds = seconds + minutes * 60 + hours * 3600 + days * 86400
time.sleep(total_seconds)
yield "message", input_data.message
yield "output_message", input_data.input_message

View File

@ -48,13 +48,13 @@ def create_test_graph() -> graph.Graph:
graph.Link(
source_id=nodes[0].id,
sink_id=nodes[2].id,
source_name="value",
source_name="result",
sink_name="values_#_a",
),
graph.Link(
source_id=nodes[1].id,
sink_id=nodes[2].id,
source_name="value",
source_name="result",
sink_name="values_#_b",
),
graph.Link(

View File

@ -39,7 +39,7 @@ async def assert_sample_graph_executions(
test_graph.id, graph_exec_id, test_user.id
)
output_list = [{"value": ["Hello"]}, {"value": ["World"]}]
output_list = [{"result": ["Hello"]}, {"result": ["World"]}]
input_list = [
{"value": "Hello", "name": "input_1"},
{"value": "World", "name": "input_2"},