From 6b8377763f7fd35cadb65472796e0aa37081ce89 Mon Sep 17 00:00:00 2001 From: Ed Morley <501702+edmorley@users.noreply.github.com> Date: Tue, 11 Mar 2025 17:55:31 +0000 Subject: [PATCH] Stop using `--link` when running Django collectstatic Since: - It causes collectstatic to fail if the app is using a Django remote storage backend (such as one that stores static assets on S3). - Using `--link` provides little benefit to apps using local storage when using WhiteNoise configured with `WHITENOISE_KEEP_ONLY_HASHED_FILES=True` (as the Python Getting Started Guide does) See: - https://github.com/heroku/buildpacks-python/issues/328 - https://docs.djangoproject.com/en/5.1/ref/contrib/staticfiles/#collectstatic Fixes #328. GUS-W-17799386. --- CHANGELOG.md | 4 ++++ src/django.rs | 2 +- src/errors.rs | 2 +- tests/django_test.rs | 8 ++++---- 4 files changed, 10 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index e1cba5d..dddfa0e 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Changed + +- Stopped using `--link` when running Django's collectstatic command, since it doesn't work with remote storage backends. ([#339](https://github.com/heroku/buildpacks-python/pull/339)) + ## [0.24.2] - 2025-03-03 ### Changed diff --git a/src/django.rs b/src/django.rs index 2d26b75..f5e43d9 100644 --- a/src/django.rs +++ b/src/django.rs @@ -40,10 +40,10 @@ pub(crate) fn run_django_collectstatic( log_info("Running 'manage.py collectstatic'"); utils::run_command_and_stream_output( Command::new("python") + // Note: We can't use `--link` since it doesn't work with remote storage backends (eg S3). .args([ MANAGEMENT_SCRIPT_NAME, "collectstatic", - "--link", // Using `--noinput` instead of `--no-input` since the latter requires Django 1.9+. "--noinput", ]) diff --git a/src/errors.rs b/src/errors.rs index 60b4227..d44bad0 100644 --- a/src/errors.rs +++ b/src/errors.rs @@ -529,7 +529,7 @@ fn on_django_collectstatic_error(error: DjangoCollectstaticError) { StreamedCommandError::NonZeroExitStatus(exit_status) => log_error( "Unable to generate Django static files", formatdoc! {" - The 'python manage.py collectstatic --link --noinput' Django management + The 'python manage.py collectstatic --noinput' Django management command to generate static files failed ({exit_status}). This is most likely due an issue in your application code or Django diff --git a/tests/django_test.rs b/tests/django_test.rs index e0ff638..cdec6c3 100644 --- a/tests/django_test.rs +++ b/tests/django_test.rs @@ -19,7 +19,7 @@ fn django_staticfiles_latest_django() { [Generating Django static files] Running 'manage.py collectstatic' - 1 static file symlinked to '/workspace/backend/staticfiles'. + 1 static file copied to '/workspace/backend/staticfiles'. "} ); }, @@ -40,9 +40,9 @@ fn django_staticfiles_legacy_django() { indoc! {" [Generating Django static files] Running 'manage.py collectstatic' - Linking '/workspace/testapp/static/robots.txt' + Copying '/workspace/testapp/static/robots.txt' - 1 static file symlinked to '/workspace/staticfiles'. + 1 static file copied to '/workspace/staticfiles'. "} ); }, @@ -148,7 +148,7 @@ fn django_staticfiles_misconfigured() { context.pack_stderr, indoc! {" [Error: Unable to generate Django static files] - The 'python manage.py collectstatic --link --noinput' Django management + The 'python manage.py collectstatic --noinput' Django management command to generate static files failed (exit status: 1). This is most likely due an issue in your application code or Django