[Django] #27658: collectstatic overwrites newer files in remote storage

10 views
Skip to first unread message

Django

unread,
Dec 29, 2016, 4:59:21 AM12/29/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: nobody
Type: Bug | Status: new
Component: | Version: 1.10
contrib.staticfiles |
Severity: Normal | Keywords: staticfiles
Triage Stage: | Has patch: 0
Unreviewed |
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 1
UI/UX: 0 |
-------------------------------------+-------------------------------------
The change to
django/contrib/staticfiles/management/commands/collectstatic.py in commit
2cd2d188516475ddf256e6267cd82c495fb5c430 causes the command to overwrite
all static files in remote storage (eg. S3), instead of only updatable
ones.

A quick workaround is to override the command and restore the previous
Command.delete_file() in the subclass, but I suppose this should be fixed.

--
Ticket URL: <https://code.djangoproject.com/ticket/27658>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Dec 29, 2016, 7:01:08 AM12/29/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* easy: 1 => 0


Comment:

Could you be more specific about the steps to reproduce the issue (ideally
without S3 involved since Django's test suite cannot rely on that)? If you
could provide a test case for `tests/staticfiles_tests` that would be
great.

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:1>

Django

unread,
Dec 30, 2016, 3:39:12 AM12/30/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+-------------------------------------
Reporter: pgcd | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Rebkavets Vitali):

This line
[https://github.com/django/django/commit/2cd2d188516475ddf256e6267cd82c495fb5c430
#diff-5e526cd393e2652c1d7f96704889a434R263 Github link]
full_path for remote storages such as S3 is always None
The clause was improperly refactored
It should look like
{{{
...
if (target_last_modified.replace(microsecond=0) >=
source_last_modified.replace(microsecond=0) and
if not full_path or full_path and not
(self.symlink ^ os.path.islink(full_path))):
...
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:2>

Django

unread,
Dec 30, 2016, 4:09:51 AM12/30/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+-------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: new

Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Description changed by Paolo Dente:

Old description:

> The change to
> django/contrib/staticfiles/management/commands/collectstatic.py in commit
> 2cd2d188516475ddf256e6267cd82c495fb5c430 causes the command to overwrite
> all static files in remote storage (eg. S3), instead of only updatable
> ones.
>
> A quick workaround is to override the command and restore the previous
> Command.delete_file() in the subclass, but I suppose this should be
> fixed.

New description:

@Tim: as far as I can tell, any non-local storage should be affected so a
possible test would require mocking Storage or the management command so
that Command.local() is False; I can try and write one. On the other hand,
it looks like @Vitali spotted the problem with the refactoring, so I don't
know how to proceed from here.

--

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:3>

Django

unread,
Dec 30, 2016, 4:12:22 AM12/30/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+-------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: new

Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Old description:

> @Tim: as far as I can tell, any non-local storage should be affected so a
> possible test would require mocking Storage or the management command so
> that Command.local() is False; I can try and write one. On the other
> hand, it looks like @Vitali spotted the problem with the refactoring, so
> I don't know how to proceed from here.

New description:

The change to
django/contrib/staticfiles/management/commands/collectstatic.py in commit
2cd2d188516475ddf256e6267cd82c495fb5c430 causes the command to overwrite
all static files in remote storage (eg. S3), instead of only updatable
ones.

A quick workaround is to override the command and restore the previous
Command.delete_file() in the subclass, but I suppose this should be fixed.

--

Comment (by Paolo Dente):

@Tim: as far as I can tell, any non-local storage should be affected so a
possible test would require mocking Storage or the management command so
that Command.local() is False; I can try and write one. On the other hand,
it looks like @Vitali spotted the problem with the refactoring, so I don't
know how to proceed from here.

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:4>

Django

unread,
Dec 30, 2016, 4:27:29 AM12/30/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: new

Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage: Accepted
Has patch: 0 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Claude Paroz):

* stage: Unreviewed => Accepted


Comment:

The next step is to write a test that demonstrates the current regression.

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:5>

Django

unread,
Dec 30, 2016, 4:38:52 AM12/30/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: new

Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Rebkavets Vitali):

* has_patch: 0 => 1


Comment:

[https://github.com/django/django/pull/7767 PR]

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:6>

Django

unread,
Dec 30, 2016, 6:13:48 AM12/30/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: new

Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Claude Paroz):

* needs_tests: 0 => 1


--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:7>

Django

unread,
Dec 30, 2016, 6:22:26 AM12/30/16
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: new

Component: contrib.staticfiles | Version: 1.10
Severity: Normal | Resolution:
Keywords: staticfiles | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by Rebkavets Vitali):

Here is a code snippet demonstrating the problem with the refactoring:

http://ideone.com/3kkY7N

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:8>

Django

unread,
Jan 2, 2017, 3:12:54 PM1/2/17
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: new
Component: contrib.staticfiles | Version: 1.10
Severity: Release blocker | Resolution:

Keywords: staticfiles | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Tim Graham):

* severity: Normal => Release blocker
* needs_tests: 1 => 0


Comment:

I added a test to the PR.

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:9>

Django

unread,
Jan 4, 2017, 1:09:38 PM1/4/17
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.10
Severity: Release blocker | Resolution: fixed

Keywords: staticfiles | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------
Changes (by Tim Graham <timograham@…>):

* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"c85831e4b7b5a7e4249df10327175b7251cb012d" c85831e4]:
{{{
#!CommitTicketReference repository=""
revision="c85831e4b7b5a7e4249df10327175b7251cb012d"
Fixed #27658 -- Prevented collectstatic from overwriting newer files in
remote storages.

Thanks revimi for the initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:10>

Django

unread,
Jan 4, 2017, 1:15:39 PM1/4/17
to django-...@googlegroups.com
#27658: collectstatic overwrites newer files in remote storage
-------------------------------------+------------------------------------
Reporter: Paolo Dente | Owner: nobody
Type: Bug | Status: closed
Component: contrib.staticfiles | Version: 1.10
Severity: Release blocker | Resolution: fixed
Keywords: staticfiles | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+------------------------------------

Comment (by Tim Graham <timograham@…>):

In [changeset:"da9b36c52d403a8de77682f4892d8890075f1289" da9b36c5]:
{{{
#!CommitTicketReference repository=""
revision="da9b36c52d403a8de77682f4892d8890075f1289"
[1.10.x] Fixed #27658 -- Prevented collectstatic from overwriting newer
files in remote storages.

Thanks revimi for the initial patch.

Backport of c85831e4b7b5a7e4249df10327175b7251cb012d from master
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27658#comment:11>

Reply all
Reply to author
Forward
0 new messages