ThereforeGames / unprompted

Templating language written for Stable Diffusion workflows. Available as an extension for the Automatic1111 WebUI.
777 stars 66 forks source link

'NoneType' object does not support item assignment #205

Closed magicbot42 closed 12 months ago

magicbot42 commented 1 year ago

Due diligence

Describe the bug

Updated unprompted today. I was consistently getting a 'NoneType' traceback until I commented out these two lines:

image

Prompt

Any and all prompts would give the same issue

Log output

`---
*** Error running process_batch: D:\SD\stable-diffusion-webui\extensions\_unprompted\scripts\unprompted.py
    Traceback (most recent call last):
      File "D:\SD\stable-diffusion-webui\modules\scripts.py", line 643, in process_batch
        script.process_batch(p, *script_args, **kwargs)
      File "D:\SD\stable-diffusion-webui\extensions\_unprompted\scripts\unprompted.py", line 808, in process_batch
        #Unprompted.shortcode_user_vars["prompts"][batch_size_index] = prompt_result
    TypeError: 'NoneType' object does not support item assignment

---`

Unprompted version

v10.1.0

WebUI version

v1.6.0

Other comments

I actually had this issue on the last update, and commented the same two lines.

ThereforeGames commented 1 year ago

Hi @magicbot42,

Thank you for reaching out. I haven't seen this error before. A few diagnostic questions if you don't mind:

Thanks!

magicbot42 commented 1 year ago

@ThereforeGames I've narrowed this down to an issue with the new override tag. I have no modifications in config_user.json. I've turned on "DEBUG" in there. I don't have a fork of automatic1111, just using git pull and it's up to date with the latest. I reverted modifications to the ui (which i only had a few)with ui_config.json. Deleting it so it made a fresh one.

With this prompt:

[override animal][choose]cat|dog[/choose][/override]
[set animal]horse[/set]
a picture of a [get animal]

I get the error message: image

And I get a picture of a horse, and a cat|dog

If I switch from using [overrride] to the inline [overrides] there is no error thrown, I get no error message, and I also only get the cat|dog.

Excited for the [override] tag, but so far can't get it to work.

magicbot42 commented 1 year ago

Added some print lines to see what was going on, and it looks like shortcode_user_vars doesn't have a prompt entry in the dictionary:

image

result: image

both: Unprompted.shortcode_user_vars["prompts"] Unprompted.shortcode_user_vars["negative_prompts"]

Appear to be None for me in this place in the code.

magicbot42 commented 1 year ago

I also just re-installed stable diffision from scratch, added the unprompted extension and i'm still getting the same error so pretty sure at this point it's nothing with my setup. Seems to be an issue with the override tag, but maybe you have something else in your setup that is satisfying those "prompts" and "negative prompts" dictionary entries that I don't have.

ThereforeGames commented 1 year ago

Hi @magicbot42,

Thank you for the additional information - I was able to reproduce the bug with [override].

I have fixed the problem internally but it will be a while before I push a new version of Unprompted. In the meantime, you can extract the attached file to your extensions/unprompted/shortcodes/basic folder then restart the WebUI. It should allow you to use [override] as intended.

override.zip

ThereforeGames commented 12 months ago

This [override] bug has been resolved in v10.2.0.

Mistborn-First-Era commented 11 months ago

I have the same problem with v10.3.1 which I just downloaded today. I am following the getting started guide; on step 4 the panda example is not working. I tried both call and file as well as with the closing [/override] and without (like the example).

2023-11-09 06:49:00,342  (WARNING)  [Unprompted.file] As of v9.14.0, [file] is a legacy shortcode and will eventually be removed in favor of [call] - the main difference is that [call] also works with functions. [00:06<00:00,  5.83it/s]
*** Error running process: C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\scripts\unprompted.py
    Traceback (most recent call last):
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shortcodes.py", line 140, in render
        return str(self.handler(self.token.keyword, self.pargs, self.kwargs, context, content))
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shared.py", line 87, in handler
        return (self.shortcode_objects[f"{keyword}"].run_block(pargs, kwargs, context, content))
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted/shortcodes\basic\override.py", line 8, in run_block
        self.Unprompted.shortcode_objects["overrides"].shortcode_overrides[pargs[0]] = self.Unprompted.parse_advanced(content,context)
    IndexError: list index out of range

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

    Traceback (most recent call last):
      File "C:\Users\Brandon\stable-diffusion-webui\modules\scripts.py", line 474, in process
        script.process(p, *script_args)
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\scripts\unprompted.py", line 723, in process
        prompt_result = Unprompted.start(apply_prompt_template(Unprompted.original_prompt, Unprompted.Config.templates.default))
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shared.py", line 176, in start
        result = self.process_string(string)
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shared.py", line 203, in process_string
        string = self.shortcode_parser.parse(self.sanitize_pre(string, self.Config.syntax.sanitize_before), context)
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shortcodes.py", line 251, in parse
        return stack.pop().render(context).replace(self.esc_start,"")
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shortcodes.py", line 55, in render
        return ''.join(child.render(context) for child in self.children)
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shortcodes.py", line 55, in <genexpr>
        return ''.join(child.render(context) for child in self.children)
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\lib_unprompted\shortcodes.py", line 144, in render
        raise ShortcodeRenderingError(msg) from ex
    lib_unprompted.shortcodes.ShortcodeRenderingError: An exception was raised while rendering the 'override' shortcode in line 1.

---
*** Error running process_batch: C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\scripts\unprompted.py
    Traceback (most recent call last):
      File "C:\Users\Brandon\stable-diffusion-webui\modules\scripts.py", line 490, in process_batch
        script.process_batch(p, *script_args, **kwargs)
      File "C:\Users\Brandon\stable-diffusion-webui\extensions\_unprompted\scripts\unprompted.py", line 830, in process_batch
        Unprompted.shortcode_user_vars["prompts"][batch_size_index] = prompt_result
    TypeError: 'NoneType' object does not support item assignment
ThereforeGames commented 11 months ago

Hi @Mistborn-First-Era,

Thanks for bringing that to my attention - I need to update the guide to match the current [override] syntax.

It should work if you do it like this:

[overrides subject="panda"][call example]

Or:

[override subject]panda[/override][call example]

Please let me know if the error persists.