Removed None initialization from response#312
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. To trigger a review, include ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
✨ Finishing Touches✨ Simplify code
Comment |
There was a problem hiding this comment.
Pull request overview
This PR updates runware.utils.instantiateDataclass to make response dataclass construction more tolerant of incomplete/empty API payloads, and introduces a compact repr for response dataclasses to reduce noise when debugging.
Changes:
- Add
_compact_dataclass_reprand apply it to dataclasses instantiated viainstantiateDataclass. - Skip
nulland blank-string values from API payloads during dataclass instantiation. - Auto-fill missing required
strfields with""when the payload omits them.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if k not in valid_fields or v is None: | ||
| continue |
| if is_dataclass(dataclass_type) and dataclass_type.__repr__ is not _compact_dataclass_repr: | ||
| dataclass_type.__repr__ = _compact_dataclass_repr | ||
| return dataclass_type(**filtered_data) |
| @@ -898,11 +914,7 @@ def instantiateDataclass(dataclass_type: Type[Any], data: dict) -> Any: | |||
| filtered_data = {} | |||
|
|
|||
| for k, v in data.items(): | |||
| if k not in valid_fields: | |||
| continue | |||
|
|
|||
| if v is None: | |||
| filtered_data[k] = None | |||
| if k not in valid_fields or v is None: | |||
| continue | |||
|
|
|||
| field_type = hints.get(k) | |||
| @@ -975,7 +987,19 @@ def instantiateDataclass(dataclass_type: Type[Any], data: dict) -> Any: | |||
| filtered_data[k] = field_type(v) | |||
| else: | |||
| filtered_data[k] = v | |||
|
|
|||
|
|
|||
| for f in fields(dataclass_type): | |||
| if ( | |||
| f.name in filtered_data | |||
| or f.default is not MISSING | |||
| or f.default_factory is not MISSING | |||
| ): | |||
| continue | |||
| if hints.get(f.name) is str: | |||
| filtered_data[f.name] = "" | |||
|
|
|||
| if is_dataclass(dataclass_type) and dataclass_type.__repr__ is not _compact_dataclass_repr: | |||
| dataclass_type.__repr__ = _compact_dataclass_repr | |||
| return dataclass_type(**filtered_data) | |||
Fixed
instantiateDataclassnow skipsnulland blank string values from API payloads instead of passing them through as explicitNoneor""instantiateDataclassfills missing requiredstrfields with""when the API leaves them out, so dataclasses likeIModelcan keepversion: strandarchitecture: stras required fieldsChanged
instantiateDataclass/instantiateDataclassList(IModel,IImage,IVideo,I3d, etc.) use a compactreprthat omits unset,None, blank string, and emptyadditional_fieldsvalues