-
-
Notifications
You must be signed in to change notification settings - Fork 3.6k
Clean up logic around how we delete files for deleted projects and inactive versions #1686
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
Changes from 4 commits
10140dd
40c2691
223b58c
b15cbbe
0457d26
b42ea66
9cd48ff
97630c1
efee905
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,14 @@ | ||
import logging | ||
|
||
from django import forms | ||
|
||
from readthedocs.builds.models import VersionAlias, Version | ||
from readthedocs.projects.models import Project | ||
from readthedocs.core.utils import trigger_build | ||
from readthedocs.projects.models import Project | ||
from readthedocs.projects.tasks import clear_artifacts | ||
|
||
|
||
log = logging.getLogger(__name__) | ||
|
||
|
||
class AliasForm(forms.ModelForm): | ||
|
@@ -33,3 +39,12 @@ def save(self, *args, **kwargs): | |
obj = super(VersionForm, self).save(*args, **kwargs) | ||
if obj.active and not obj.built and not obj.uploaded: | ||
trigger_build(project=obj.project, version=obj) | ||
|
||
def clean(self): | ||
cleaned_data = super(VersionForm, self).clean() | ||
if self.instance.pk is not None: # new instance only | ||
if self.instance.active is True and cleaned_data['active'] is False: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Django will actually change the Therefore I think the best place to grab old, unsaved values is in the In this particular case you could use the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fancy, didn't know about that addition. |
||
log.info('Removing files for version %s' % self.instance.slug) | ||
clear_artifacts.delay(version_pk=self.instance.pk) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why is clearing artifacts happening in the clean method? Validating a form should not have sideeffects. |
||
self.instance.built = False | ||
return cleaned_data |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ | |
REPO_TYPE_HG, GITHUB_URL, | ||
GITHUB_REGEXS, BITBUCKET_URL, | ||
BITBUCKET_REGEXS) | ||
from readthedocs.projects.tasks import clear_artifacts | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this introduced a cyclic dependency: https://travis-ci.org/rtfd/readthedocs.org/jobs/81886399#L213 |
||
|
||
from .constants import (BUILD_STATE, BUILD_TYPES, VERSION_TYPES, | ||
LATEST, NON_REPOSITORY_VERSIONS, STABLE, | ||
|
@@ -158,6 +159,12 @@ def save(self, *args, **kwargs): | |
self.project.sync_supported_versions() | ||
return obj | ||
|
||
def delete(self, *args, **kwargs): | ||
log.info('Removing files for version %s' % self.slug) | ||
clear_artifacts.delay(version_pk=self.pk) | ||
super(Version, self).delete(*args, **kwargs) | ||
|
||
|
||
@property | ||
def identifier_friendly(self): | ||
'''Return display friendly identifier''' | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The comment is wrong or misleading, this will actually only act on "old" instances in the sense of ones that already existed before the form was saved.