Skip to content

Fix nested SettingsModel defaults - #1059

Draft
BigRoy wants to merge 1 commit into
developfrom
bugfix/fix_nested_settingsmodel_defaults
Draft

BigRoy wants to merge 1 commit into
developfrom
bugfix/fix_nested_settingsmodel_defaults

Conversation

@BigRoy

@BigRoy BigRoy commented Aug 11, 2026

Copy link
Copy Markdown
Member

Description of changes

Fix nested SettingsModels like:

class WriteKnobsModel(SettingsModel):
    custom: list[KnobModel] = SettingsField(
        title="Additional Knobs",
        default=[
            KnobModel(
                type="text",
                name="mov64_codec",
                text="ap4h",
            ),
            KnobModel(
                type="boolean",
                name="mov64_write_timecode",
                boolean=True,
            )
        ]
    )

class IntermediateOutputModel(BaseSettingsModel):
    write_knobs: WriteKnobsModel = SettingsField(
        default_factory=WriteKnobsModel,
        title="Write Knobs",
        description=(
            "Configure knobs on the output write node"
        )
    )
    
    
class MainModel(BaseSettingsModel):
    outputs: list[IntermediateOutputModel] = SettingsField(
        default_factory=list,
        title="Baking streams"
    )

The defaults to custom key should automatically be set when adding a new entry to outputs in the Settings in frontend.

Technical details

I feel like this 'fix' is way too convoluted and there must be something wrong - but just putting this as draft because it does resolve the issue here. However we should likely need to look at some other 'correct fix'.

Additional context

Solves case described here: ynput/ayon-nuke#344 (comment)

This is not a high priority at all.

@moonyuet

Copy link
Copy Markdown
Member

It is working in my side with ynput/ayon-nuke#344 (comment) through testing.

@BigRoy

BigRoy commented Aug 12, 2026

Copy link
Copy Markdown
Member Author

This is just there to show that there's a bug that is solvable. The fix (created by AI) I'd say feels very off. I don't think we'd need to do this much mumbo jumbo and there must be an easier way.

What I really think the issue is is that in most integrations some BaseSettingModels may not define default for all attributes, e.g. a str attribute might not explicitly have default="" passed or alike. And maybe as we convert the schemas we need to stop deeper conversion because we can't initialize the base MyModel() to get to the defaults because you can't actually initialize it without passing the arguments that don't have defaults, perhaps? No idea. Anyway, it's not urgent, but good to be aware there is a bug here where defaults like in the Nuke example don't come through.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR augments exported settings JSON schemas so that defaults for nested BaseSettingsModel fields (especially those created via default_factory and containing further nested defaults) are explicitly populated in the schema, enabling the frontend to prefill newly added list entries with deep defaults.

Changes:

  • Added populate_schema_defaults() to traverse a settings model + schema and inject missing default values (including nested model defaults).
  • Called populate_schema_defaults() in addon studio, site, and project schema endpoints before postprocess_settings_schema().

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
ayon_server/settings/postprocess.py Adds schema traversal logic to populate missing defaults (including nested settings models).
api/addons/studio_settings.py Populates schema defaults for addon studio settings schema responses.
api/addons/site_settings.py Populates schema defaults for addon site settings schema responses.
api/addons/project_settings.py Populates schema defaults for addon project settings schema responses.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +97 to +101
if "default" not in child_schema:
default = get_field_default(field)
if default is not missing:
child_schema["default"] = default

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

type: bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants