Skip to content

fix(nodes): better defaults parsing and error handling #8018

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 20, 2025

Conversation

psychedelicious
Copy link
Collaborator

Summary

Fixes and better error handling for invalid invocation field default values.

Related Issues / Discussions

Discord thread: https://discord.com/channels/1020123559063990373/1149506274971631688/1374029733423087636

QA Instructions

Using this repo as a test https://github.com/mickr777/imagetoasciiimage

Before

  • No error in launcher/python terminal, just looks fine
  • UI hangs at loading screen
  • Error like this in the JS console of browser
    image

After

  • Big error in launcher/python terminal
  • UI does not hang
  • If, somehow, the invocation gets past the python safeguards, instead of hanging the UI, the error is logged and the UI loads.

Example terminal error:

[2025-05-20 08:30:45,802]::[InvokeAI]::ERROR --> Failed to load node pack imagetoasciiimage (may have partially loaded):
Traceback (most recent call last):
  File "/home/bat/Documents/Code/InvokeAI/invokeai/app/invocations/baseinvocation.py", line 530, in validate_field_default
    TempDefaultValidator.model_validate({field_name: orig_default})
  File "/home/bat/Documents/Code/InvokeAI/.venv/lib/python3.12/site-packages/pydantic/main.py", line 703, in model_validate
    return cls.__pydantic_validator__.validate_python(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
pydantic_core._pydantic_core.ValidationError: 1 validation error for ImageToAAInvocation
local_font
  Input should be 'None' [type=literal_error, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.11/v/literal_error

The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/bat/Documents/Code/InvokeAI/invokeai/app/invocations/load_custom_nodes.py", line 69, in load_custom_nodes
    spec.loader.exec_module(module)
  File "<frozen importlib._bootstrap_external>", line 995, in exec_module
  File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
  File "/home/bat/invokeai-4.0.0/nodes/imagetoasciiimage/__init__.py", line 2, in <module>
    from .i2aa_anyfont import ImageToAAInvocation
  File "/home/bat/invokeai-4.0.0/nodes/imagetoasciiimage/i2aa_anyfont.py", line 116, in <module>
    @invocation(
     ^^^^^^^^^^^
  File "/home/bat/Documents/Code/InvokeAI/invokeai/app/invocations/baseinvocation.py", line 594, in wrapper
    validate_field_default(cls.__name__, field_name, invocation_type, annotation, field_info)
  File "/home/bat/Documents/Code/InvokeAI/invokeai/app/invocations/baseinvocation.py", line 532, in validate_field_default
    raise InvalidFieldError(
invokeai.app.invocations.baseinvocation.InvalidFieldError: Default value for field "local_font" on invocation "I2AA_AnyFont" is invalid, 1 validation error for ImageToAAInvocation
local_font
  Input should be 'None' [type=literal_error, input_value=None, input_type=NoneType]
    For further information visit https://errors.pydantic.dev/2.11/v/literal_error

Merge Plan

n/a

Checklist

  • The PR has a short but descriptive title, suitable for a changelog
  • Tests added / updated (if applicable)
  • Documentation added / updated (if applicable)
  • Updated What's New copy (if doing a release after this PR)

@github-actions github-actions bot added python PRs that change python files invocations PRs that change invocations frontend PRs that change frontend files labels May 19, 2025
@psychedelicious psychedelicious enabled auto-merge (rebase) May 20, 2025 00:42
For example:
```py
my_field: Literal["foo", "bar"] | None = InputField(default=None)
```

Previously, this would cause a field parsing error and prevent the app from loading.

Two fixes:
- This type annotation and resultant schema are now parsed correctly
- Error handling added to template building logic to prevent the hang at startup when an error does occur
@psychedelicious psychedelicious force-pushed the psyche/fix/nodes/default-parsing branch from 2fc85c7 to 98b16f9 Compare May 20, 2025 00:42
@psychedelicious psychedelicious merged commit 19ecdb1 into main May 20, 2025
12 checks passed
@psychedelicious psychedelicious deleted the psyche/fix/nodes/default-parsing branch May 20, 2025 00:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
frontend PRs that change frontend files invocations PRs that change invocations python PRs that change python files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants