Skip to content
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

Avoid top-level versioned_static calls #89

Merged
merged 3 commits into from
Jun 17, 2024
Merged

Conversation

tomkins
Copy link
Contributor

@tomkins tomkins commented May 30, 2024

Closes #88

To fully test - upload an image in the admin and check that the AI generation button still works.

I'm fairly confident in the media fix (it's similar to wagtail/wagtail#5694), however the CI testing might be slightly opinionated. My personal opinion - CI should run static file creation (webpack), manifest storage should be used to avoid missing files, and migrations should be tested in projects.

However - happy for feedback if this isn't what you want!

tomkins added 3 commits May 30, 2024 21:45
makemigrations is the key check which may fail
Prevent versioned_static from being called too early
@tomkins tomkins marked this pull request as ready for review May 30, 2024 21:17
@zerolab
Copy link
Collaborator

zerolab commented Jun 4, 2024

Thank you for this @tomkins
Will try to review ASAP (but it may be it happens during the sprints at Wagtail Space NL next week)

"staticfiles": {
"BACKEND": os.environ.get(
"STATICFILES_STORAGE",
"django.contrib.staticfiles.storage.StaticFilesStorage",
Copy link
Member

Choose a reason for hiding this comment

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

question: Is there a particular reason to make this an env var? Why not always use ManifestStaticFilesStorage?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Testing with ManifestStaticFilesStorage requires that you've done collectstatic beforehand, for example:

STATICFILES_STORAGE=django.contrib.staticfiles.storage.ManifestStaticFilesStorage pytest

Fails with:

ValueError: Missing staticfiles manifest entry for 'wagtailadmin/css/core.css'

As the static files aren't in place. But if you do:

STATICFILES_STORAGE=django.contrib.staticfiles.storage.ManifestStaticFilesStorage ./testmanage.py collectstatic --no-input
STATICFILES_STORAGE=django.contrib.staticfiles.storage.ManifestStaticFilesStorage pytest

It works as expected - the static files are in place.

I've added the additional commands in tox.ini that will run collectstatic beforehand if you're running inside tox. If you're just doing quick development outside of tox - then it defaults to StaticFilesStorage - which is faster/easier if you need a quick feedback loop.

For most of our projects at DEV we try and have some form of CI that runs with ManifestStaticFilesStorage, as that's what we deploy with - so running CI with the same storage helps reduce any errors.

It's possibly a bit opinionated, but I've tried to follow something roughly along the lines of: https://github.com/wagtail/wagtail/blob/main/wagtail/test/settings.py#L68.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation!

@tomusher
Copy link
Member

tomusher commented Jun 7, 2024

This all looks sensible to me, thanks @tomkins! One minor question for my own education but other than that, happy to get this in.

@tomusher tomusher merged commit a9e4391 into wagtail:main Jun 17, 2024
11 checks passed
@tomkins tomkins deleted the media-fixes branch June 17, 2024 09:21
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.

Top level versioned_static causing problems with ManifestStaticFilesStorage
3 participants