feat: initialize inputs in IImageInference post-init#245
Closed
rensortino wants to merge 1 commit intoRunware:mainfrom
Closed
feat: initialize inputs in IImageInference post-init#245rensortino wants to merge 1 commit intoRunware:mainfrom
rensortino wants to merge 1 commit intoRunware:mainfrom
Conversation
Collaborator
|
Thanks @rensortino |
Collaborator
|
Check this #246 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
When
IImageInferenceis constructed with inputs passed as a plain dict (e.g.{"referenceImages": [...]}) instead of anIInputsinstance, the SDK later calls_addOptionalFieldwhich invokesinputs.to_request_dict()— a method that only exists on theIInputsdataclass. This results in anAttributeErrorat runtime.Adds a
__post_init__hook toIImageInferencethat automatically converts a raw dict value for inputs into a properIInputsinstance viaIInputs(**self.inputs), matching the pattern already used byIInputsitself for its own__post_init__logic.Related issue
Fixes #244
Problem
Passing inputs as a dictionary when constructing
IImageInference— a natural pattern when building request params dynamically — fails because the dataclass stores the raw dict rather than anIInputsobject:This raises an
AttributeError: 'dict' object has no attribute 'to_request_dict' during serialization in _addOptionalField.Solution
A
__post_init__method onIImageInferencedetects when inputs is not None and not already anIInputsinstance, and coerces it:This allows users to pass either an
IInputsobject or a plain dictionary, with both working seamlessly.