Skip to content

feat: initialize inputs in IImageInference post-init#245

Closed
rensortino wants to merge 1 commit intoRunware:mainfrom
rensortino:feat/flux-input-validation
Closed

feat: initialize inputs in IImageInference post-init#245
rensortino wants to merge 1 commit intoRunware:mainfrom
rensortino:feat/flux-input-validation

Conversation

@rensortino
Copy link

Summary

When IImageInference is constructed with inputs passed as a plain dict (e.g. {"referenceImages": [...]}) instead of an IInputs instance, the SDK later calls _addOptionalField which invokes inputs.to_request_dict() — a method that only exists on the IInputs dataclass. This results in an AttributeError at runtime.

Adds a __post_init__ hook to IImageInference that automatically converts a raw dict value for inputs into a proper IInputs instance via IInputs(**self.inputs), matching the pattern already used by IInputs itself 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 an IInputs object:

request = IImageInference(
    positivePrompt="...",
    model="bfl:7@1",
    inputs={"referenceImages": [image_data_uri]},  # plain dict → crash
)

This raises an AttributeError: 'dict' object has no attribute 'to_request_dict' during serialization in _addOptionalField.

Solution

A __post_init__ method on IImageInference detects when inputs is not None and not already an IInputs instance, and coerces it:

def __post_init__(self):
    if self.inputs is not None and not isinstance(self.inputs, IInputs):
        self.inputs = IInputs(**self.inputs)

This allows users to pass either an IInputs object or a plain dictionary, with both working seamlessly.

@Sirsho1997
Copy link
Collaborator

Thanks @rensortino
Will be adding such post_init() for all other taskTypes as well.

@Sirsho1997
Copy link
Collaborator

Check this #246

@Sirsho1997 Sirsho1997 closed this Feb 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flux inference fails: AttributeError: 'dict' object has no attribute 'to_request_dict'

2 participants