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 calling versioned_static from styleguide on application startup #11647

Closed
wants to merge 2 commits into from

Conversation

gasman
Copy link
Collaborator

@gasman gasman commented Feb 14, 2024

Fixes #11643. Change class Media into a media property to prevent it from being called on application startup, and add a check to our CI to fail loudly if this happens in future.

@gasman gasman added this to the 6.0.1 milestone Feb 14, 2024
Copy link

squash-labs bot commented Feb 14, 2024

Manage this branch in Squash

Test this branch here: https://gasmanfixversionedstatic-on-st-08a4s.squash.io

@gasman gasman force-pushed the fix/versionedstatic-on-startup branch from 21d3353 to 148e14a Compare February 14, 2024 12:51
@gasman
Copy link
Collaborator Author

gasman commented Feb 14, 2024

See https://github.com/wagtail/wagtail/actions/runs/7901444476 for an instance of this failure being triggered.

Copy link
Member

@laymonage laymonage left a comment

Choose a reason for hiding this comment

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

Thanks! I can confirm that the fix works, but I'm not so sure about the testing approach. I've found a different way that works by setting DEBUG=False, will put up a separate PR for it.

Comment on lines +39 to +42
if os.environ.get("WAGTAIL_FAIL_ON_VERSIONED_STATIC", "0") == "1":

base_url = static(path)
def versioned_static(path):
raise Exception(
Copy link
Member

@laymonage laymonage Feb 15, 2024

Choose a reason for hiding this comment

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

I'm not convinced this is the best way to test this... it seems too specific and doesn't really simulate the issue, which is doing collectstatic with DEBUG=False. If we don't have a similar setup in our CI, we potentially could run into similar issues that's not caused by versioned_static (e.g. the reason why we added collectstatic in our CI like #9002).

I've found a different approach that works by setting DEBUG = False via an environment variable, will make a separate PR now.

Copy link
Member

@laymonage laymonage Feb 15, 2024

Choose a reason for hiding this comment

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

Also, just to add: I agree it is nice to show a more helpful message like this when developers put versioned_static at startup, but the problem is they need to explicitly set WAGTAIL_FAIL_ON_VERSIONED_STATIC to 1, and neither this setting nor versioned_static are documented, so they have to know that this is an issue to detect the issue (if that makes sense). If it's documented (or defaults to 1), I wouldn't mind us having these :D

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This isn't really intended to be a test in the sense of replicating something that would happen on a real-world site - it's more of a quality check on the Wagtail codebase, like test_migrations, to ensure that CI fails loudly if this has been overlooked. It doesn't need to be documented, as it's not intended for developers to run it outside of the CI environment.

Defaulting to 1 wouldn't work, because that would break legitimate uses of versioned_static during runtime too. I don't think there's any good way to distinguish between valid and invalid uses of versioned_static in code, so the idea is that the CI runner enables the WAGTAIL_FAIL_ON_VERSIONED_STATIC flag for a command such as manage.py check or manage.py collectstatic that isn't expected to render any views - if this fails, we know it's an invalid use of versioned_static.

Copy link
Member

@laymonage laymonage Feb 15, 2024

Choose a reason for hiding this comment

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

Yeah, defaulting it to 1 would likely require some nasty hacks so that the function knows whether it's run at startup or not. OK then, in that case I'm happy to add this in. I still think it's worth having collectstatic run with DEBUG = False though (no need to backport that one), so I'll rebase my other PR after this is merged if that's OK.

gasman added a commit that referenced this pull request Feb 15, 2024
gasman added a commit that referenced this pull request Feb 15, 2024
@gasman
Copy link
Collaborator Author

gasman commented Feb 15, 2024

Merged in 263d3c6 (main) / 567e56a (stable/6.0.x)

@gasman gasman closed this Feb 15, 2024
@lb-
Copy link
Member

lb- commented Feb 17, 2024

Thanks all, my apologies for missing this when doing #11164

Glad we have an automated way to test for this in the future.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Issue with Missing Static File wagtailstyleguide/css/animate-progress.css in Wagtail 6.0 with DEBUG=False
3 participants