Merge lp:~michael.nelson/ubuntu-webcatalog/fix-import-crash into lp:ubuntu-webcatalog

Proposed by Michael Nelson
Status: Merged
Approved by: Łukasz Czyżykowski
Approved revision: 111
Merged at revision: 109
Proposed branch: lp:~michael.nelson/ubuntu-webcatalog/fix-import-crash
Merge into: lp:ubuntu-webcatalog
Diff against target: 60 lines (+9/-6)
3 files modified
src/webcatalog/forms.py (+6/-3)
src/webcatalog/management/commands/import_app_install_data.py (+0/-2)
src/webcatalog/tests/test_forms.py (+3/-1)
To merge this branch: bzr merge lp:~michael.nelson/ubuntu-webcatalog/fix-import-crash
Reviewer Review Type Date Requested Status
Canonical Consumer Applications Hackers Pending
Review via email: mp+102795@code.launchpad.net

Commit message

Don't save an application without a distroseries during import.

Description of the change

When the initial error appeared:

https://bugs.launchpad.net/ubuntu-webcatalog/+bug/985901

the fix was to ensure the app was saved so that when the ApplicationForm.save() method tried to add the related screenshots, it didn't error. But the app cannot be saved without a distroseries either.

This branch updates the ApplicationForm so that it includes the distroseries in its cleaned data, then during save, it saves the app *with* the distroseries before trying to add any related screenshots (and removes the option of commit=False)

`fab test`

I'll test this on the vps once it's landed.

To post a comment you must log in.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/webcatalog/forms.py'
2--- src/webcatalog/forms.py 2012-03-26 20:48:43 +0000
3+++ src/webcatalog/forms.py 2012-04-20 06:45:22 +0000
4@@ -62,7 +62,7 @@
5
6 class Meta:
7 model = Application
8- exclude = ('distroseries', 'for_purchase', 'archive_id', 'price')
9+ exclude = ('for_purchase', 'archive_id', 'price')
10
11 @classmethod
12 def get_form_from_desktop_data(cls, str_data, distroseries):
13@@ -78,6 +78,7 @@
14 package_name=data['package_name'], distroseries=distroseries)
15 except Application.DoesNotExist:
16 instance = None
17+ data['distroseries'] = distroseries.id
18 return cls(data=data, instance=instance)
19
20 def clean(self):
21@@ -95,8 +96,10 @@
22
23 return cleaned_data
24
25- def save(self, commit=True):
26- app = super(ApplicationForm, self).save(commit)
27+ def save(self):
28+ # We don't provide a commit=False option as we have
29+ # to commit to be able to add the screenshots.
30+ app = super(ApplicationForm, self).save()
31 screenshot_url = self.cleaned_data['screenshot_url']
32 if screenshot_url:
33 if screenshot_url not in app.screenshots:
34
35=== modified file 'src/webcatalog/management/commands/import_app_install_data.py'
36--- src/webcatalog/management/commands/import_app_install_data.py 2012-04-19 21:20:32 +0000
37+++ src/webcatalog/management/commands/import_app_install_data.py 2012-04-20 06:45:22 +0000
38@@ -190,8 +190,6 @@
39
40 if form.is_valid():
41 app = form.save()
42- app.distroseries = distroseries
43- app.save()
44 app.update_departments()
45 self.add_icon_to_app(app, icon_dir)
46 if self.verbosity > 1:
47
48=== modified file 'src/webcatalog/tests/test_forms.py'
49--- src/webcatalog/tests/test_forms.py 2012-03-26 20:48:43 +0000
50+++ src/webcatalog/tests/test_forms.py 2012-04-20 06:45:22 +0000
51@@ -160,8 +160,10 @@
52 # - It adds a significant delay to tests unless carefully mocked
53 # - It doesn't provide a real benefit as 99% of the time the field
54 # is populated by a script that doesn't have typo issues.
55+ distroseries = self.factory.make_distroseries()
56 form = ApplicationForm(dict(screenshot_url='http://foo.com:42/broken',
57- section='required', name='required', package_name='required'))
58+ section='required', name='required', package_name='required',
59+ distroseries=distroseries.id))
60 self.assertTrue(form.is_valid())
61
62

Subscribers

People subscribed via source and target branches