wagtail / wagtail-ai

Get help with your Wagtail content using AI superpowers.

Home Page:https://wagtail-ai.readthedocs.io/latest

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Top level versioned_static causing problems with ManifestStaticFilesStorage

tomkins opened this issue · comments

Related:

Currently wagtail-ai has versioned_static calls that makes it tricky to run certain commands before ./manage.py collectstatic. An example is that I can't do ./manage.py migrate when ManifestStaticFilesStorage is enabled:

(devsoc) ➜  devsoc git:(wagtail-6.1.2) ✗ ./manage.py migrate
Traceback (most recent call last):
  File "/Users/tomkins/Sites/devsoc/./manage.py", line 22, in <module>
    main()
  ...
  File "/Users/tomkins/.virtualenvs/devsoc/lib/python3.12/site-packages/django/contrib/staticfiles/storage.py", line 516, in stored_name
    raise ValueError(
ValueError: Missing staticfiles manifest entry for 'wagtail_ai/image_description.js'

It's not as bad as other times when Wagtail has had this issue (being impossible to run collectstatic because the static file wasn't collected yet), but would be nice to fix.

I've just encountered this myself with version 2.1.0 in a Docker container build. In my case it is collectstatic that's failing, meaning I'm caught in the vicious cycle of not being able to run it because it hasn't been run yet 😮‍💨

@tomkins were you able to run collectstatic with the manifest backend? Do you know which version you were using? It looks like the changes in #89 would fix my issue too, but I'm a bit baffled that I'm not able to run collectstatic at all.

In my case, it's an import-time call to versioned_static in wagtail_ai.forms that's causing the issue:

> [web 6/6] RUN <<EOF (SECRET_KEY=none django-admin collectstatic --noinput --clear):
0.992 WARNING:root:No DATABASE_URL environment variable set, and so no databases setup
9.196 Traceback (most recent call last):
9.196   File "/venv/bin/django-admin", line 8, in <module>
9.196     sys.exit(execute_from_command_line())
9.196              ^^^^^^^^^^^^^^^^^^^^^^^^^^^
9.197   File "/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 442, in execute_from_command_line
9.197     utility.execute()
9.197   File "/venv/lib/python3.12/site-packages/django/core/management/__init__.py", line 416, in execute
9.197     django.setup()
9.197   File "/venv/lib/python3.12/site-packages/django/__init__.py", line 24, in setup
9.198     apps.populate(settings.INSTALLED_APPS)
9.198   File "/venv/lib/python3.12/site-packages/django/apps/registry.py", line 124, in populate
9.198     app_config.ready()
9.198   File "/venv/lib/python3.12/site-packages/wagtail/snippets/apps.py", line 17, in ready
9.198     register_deferred_snippets()
9.198   File "/venv/lib/python3.12/site-packages/wagtail/snippets/models.py", line 121, in register_deferred_snippets
9.198     _register_snippet_immediately(registerable, viewset)
9.198   File "/venv/lib/python3.12/site-packages/wagtail/snippets/models.py", line 110, in _register_snippet_immediately
9.198     viewsets.register(registerable)
9.199   File "/venv/lib/python3.12/site-packages/wagtail/admin/viewsets/__init__.py", line 30, in register
9.199     viewset.on_register()
9.199   File "/venv/lib/python3.12/site-packages/wagtail/snippets/views/snippets.py", line 1221, in on_register
9.199     self.register_snippet_model()
9.199   File "/venv/lib/python3.12/site-packages/wagtail/snippets/views/snippets.py", line 1206, in register_snippet_model
9.200     snippet_models = get_snippet_models()
9.200                      ^^^^^^^^^^^^^^^^^^^^
9.200   File "/venv/lib/python3.12/site-packages/wagtail/snippets/models.py", line 33, in get_snippet_models
9.200     search_for_hooks()
9.200   File "/venv/lib/python3.12/site-packages/wagtail/hooks.py", line 106, in search_for_hooks
9.200     list(get_app_submodules("wagtail_hooks"))
9.200   File "/venv/lib/python3.12/site-packages/wagtail/utils/apps.py", line 23, in get_app_submodules
9.200     yield name, import_module(f"{name}.{submodule_name}")
9.200                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9.201   File "/usr/local/lib/python3.12/importlib/__init__.py", line 90, in import_module
9.201     return _bootstrap._gcd_import(name[level:], package, level)
9.201            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9.201   File "<frozen importlib._bootstrap>", line 1387, in _gcd_import
9.201   File "<frozen importlib._bootstrap>", line 1360, in _find_and_load
9.201   File "<frozen importlib._bootstrap>", line 1331, in _find_and_load_unlocked
9.201   File "<frozen importlib._bootstrap>", line 935, in _load_unlocked
9.201   File "<frozen importlib._bootstrap_external>", line 995, in exec_module
9.201   File "<frozen importlib._bootstrap>", line 488, in _call_with_frames_removed
9.201   File "/venv/lib/python3.12/site-packages/wagtail_ai/wagtail_hooks.py", line 12, in <module>
9.202     from .views import describe_image, prompt_viewset, text_completion
9.202   File "/venv/lib/python3.12/site-packages/wagtail_ai/views.py", line 18, in <module>
9.202     from .forms import DescribeImageApiForm, PromptForm
9.202   File "/venv/lib/python3.12/site-packages/wagtail_ai/forms.py", line 52, in <module>
9.202     class DescribeImageForm(BaseImageForm):
9.202   File "/venv/lib/python3.12/site-packages/wagtail_ai/forms.py", line 61, in DescribeImageForm
9.202     class Media:
9.202   File "/venv/lib/python3.12/site-packages/wagtail_ai/forms.py", line 62, in Media
9.202     js = [versioned_static("wagtail_ai/image_description.js")]
9.202           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9.202   File "/venv/lib/python3.12/site-packages/wagtail/admin/staticfiles.py", line 60, in versioned_static
9.202     base_url = static(path)
9.202                ^^^^^^^^^^^^
9.202   File "/venv/lib/python3.12/site-packages/django/templatetags/static.py", line 179, in static
9.203     return StaticNode.handle_simple(path)
9.203            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9.203   File "/venv/lib/python3.12/site-packages/django/templatetags/static.py", line 129, in handle_simple
9.203     return staticfiles_storage.url(path)
9.203            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9.203   File "/venv/lib/python3.12/site-packages/django/contrib/staticfiles/storage.py", line 203, in url
9.205     return self._url(self.stored_name, name, force)
9.205            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
9.205   File "/venv/lib/python3.12/site-packages/django/contrib/staticfiles/storage.py", line 182, in _url
9.205     hashed_name = hashed_name_func(*args)
9.205                   ^^^^^^^^^^^^^^^^^^^^^^^
9.205   File "/venv/lib/python3.12/site-packages/django/contrib/staticfiles/storage.py", line 516, in stored_name
9.205     raise ValueError(
9.205 ValueError: Missing staticfiles manifest entry for 'wagtail_ai/image_description.js'

@bcdickinson for us - as this is failing in our CI, I haven't updated any existing site to wagtail-ai 2.1.0 yet. I've setup a separate demo site for another project and switched away from manifest storage temporarily to be able to show it until there's a new release.

I've played around server side, trying to install wagtail-ai 2.1.0 directly in the virtualenv, removing staticfiles.json, running collectstatic - and it seems to work. There could be something I'm missing in my testing there though, or maybe you've got imports that are loading files with versioned_static earlier.

But yes, it's definitely possible that you end up with a situation where you can't run collectstatic (such as wagtail/wagtail#5632 and wagtail/wagtail#5644).

I've just released 2.1.1 with @tomkins's fix in, this seems to have resolved the build issue @bcdickinson was seeing.

Confirmed as fixed with 2.1.1 - thanks!