|
1 | 1 | from dataclasses import dataclass, field |
2 | 2 | from typing import Any, Optional |
3 | 3 | from .schema import FieldSchema, ContentMediaType |
| 4 | +import copy |
4 | 5 |
|
5 | 6 | __all__ = ["HandleDef", "InputHandleDef", "OutputHandleDef"] |
6 | 7 |
|
@@ -45,12 +46,15 @@ class HandleDef(DataDict): |
45 | 46 |
|
46 | 47 | def __init__(self, **kwargs): |
47 | 48 | for key, value in kwargs.items(): |
48 | | - object.__setattr__(self, key, value) |
| 49 | + if key == 'json_schema' and isinstance(value, dict): |
| 50 | + object.__setattr__(self, key, copy.deepcopy(value)) |
| 51 | + else: # For other attributes, we can use the default behavior of object.__setattr__ |
| 52 | + object.__setattr__(self, key, value) |
49 | 53 | if "handle" not in kwargs: |
50 | 54 | raise ValueError("missing attr key: 'handle'") |
51 | 55 | json_schema = self.json_schema |
52 | 56 | if json_schema is not None and not isinstance(json_schema, FieldSchema): |
53 | | - object.__setattr__(self, "_raw_json_schema", json_schema) |
| 57 | + object.__setattr__(self, "_raw_json_schema", copy.deepcopy(json_schema)) |
54 | 58 | object.__setattr__(self, "json_schema", FieldSchema.generate_schema(json_schema)) |
55 | 59 |
|
56 | 60 | def check_handle_type(self, type: ContentMediaType) -> bool: |
|
0 commit comments