Merge lp:~andrea.corbellini/launchpad/fix-406523 into lp:launchpad

Proposed by Andrea Corbellini
Status: Merged
Merged at revision: not available
Proposed branch: lp:~andrea.corbellini/launchpad/fix-406523
Merge into: lp:launchpad
Diff against target: None lines
To merge this branch: bzr merge lp:~andrea.corbellini/launchpad/fix-406523
Reviewer Review Type Date Requested Status
Paul Hummer (community) Approve
Leonard Richardson (community) Approve
Tom Haddon Approve
Review via email: mp+9439@code.launchpad.net
To post a comment you must log in.
Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

= Summary =

Bugs, blueprints and answers needs attachments to be inserted in comments. Currently to limit the size bug comments attachments there's a validator in `canonical.launchpad.validators.bugattachments`. It wouldn't be useful to create new validators that do the same thing in the same way for blueprints and answers too.

== Pre-implementation notes ==

I've discussed this change with sinzui and he agreed.

== Implementation details ==

With this branch I've renamed `bugattachments` to `attachments`, making it more generic. I've also renamed the function `bug_attachment_size_constraint()` to `attachment_size_constraint()` and the configuration item `max_bug_attachment_size` to `max_attachment_size`.

== Tests ==

$ bin/test -vv -t lib/lp/bugs/tests/../stories/bugs/xx-bug-comment-attach-file.txt -t lib/lp/bugs/tests/../doc/bugattachments.txt
Running tests at level 1

Running canonical.testing.layers.LaunchpadFunctionalLayer tests:
  Set up canonical.testing.layers.BaseLayer in 0.004 seconds.
  Set up canonical.testing.layers.DatabaseLayer in 0.806 seconds.
  Set up canonical.testing.layers.LibrarianLayer in 9.755 seconds.
  Set up canonical.testing.layers.LaunchpadLayer in 0.000 seconds.
  Set up canonical.testing.layers.FunctionalLayer in 7.743 seconds.
  Set up canonical.testing.layers.GoogleServiceLayer in 1.539 seconds.
  Set up canonical.testing.layers.LaunchpadFunctionalLayer in 0.000 seconds.
  Running:
 lib/lp/bugs/tests/../doc/bugattachments.txt
  Ran 27 tests with 0 failures and 0 errors in 6.076 seconds.
Running canonical.testing.layers.PageTestLayer tests:
  Set up canonical.testing.layers.PageTestLayer in 0.001 seconds.
  Running:
 lib/lp/bugs/tests/../stories/bugs/xx-bug-comment-attach-file.txt
  Ran 8 tests with 0 failures and 0 errors in 20.382 seconds.
Tearing down left over layers:
  Tear down canonical.testing.layers.PageTestLayer in 0.000 seconds.
  Tear down canonical.testing.layers.LaunchpadFunctionalLayer in 0.000 seconds.
  Tear down canonical.testing.layers.LaunchpadLayer in 0.000 seconds.
  Tear down canonical.testing.layers.LibrarianLayer in 0.410 seconds.
  Tear down canonical.testing.layers.GoogleServiceLayer in 0.087 seconds.
  Tear down canonical.testing.layers.FunctionalLayer ... not supported
  Tear down canonical.testing.layers.DatabaseLayer in 0.048 seconds.
  Tear down canonical.testing.layers.BaseLayer in 0.000 seconds.
Total: 35 tests, 0 failures, 0 errors in 48.292 seconds.

== lint ==

`make lint` did not return any error in my code.

Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

I forgot to mention that this branch is needed in order to get bug 49698 fixed.

Revision history for this message
Leonard Richardson (leonardr) wrote :

Thanks for doing this branch. It looks like a good first step.

I'm very suspicious of the unconditional return statement in line 51. It looks like you added that during development and that it should be removed.

Other than that, this branch looks good. Approved*. I'm a trainee reviewer so you'll need to get rockstar to approve my change, and then have an admin look at it because it changes configuration.

review: Approve
Revision history for this message
Paul Hummer (rockstar) wrote :

Hi Andreas-

  Thanks for this work! I agree with Leonard concerning the changes to lib/canonical/database/revision.py - I think it would be best to just revert both changes in there. Yes, you're removing a line, but we generally don't make whitespace changes to a file unless we actually edit it so that we don't cause spurious conflicts. Other than that, thanks for looking into this!

review: Approve
Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

> Thanks for doing this branch. It looks like a good first step.
>
> I'm very suspicious of the unconditional return statement in line 51. It looks
> like you added that during development and that it should be removed.

I've removed the `return` in the last revision: http://bazaar.launchpad.net/~andrea-bs/launchpad/fix-406523/revision/9007.
The reason why you see it in the diff is because is hasn't been updated after my last push (there's a bug about this somewhere).

> Other than that, this branch looks good. Approved*. I'm a trainee reviewer so
> you'll need to get rockstar to approve my change, and then have an admin look
> at it because it changes configuration.

Thanks for your help!

Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

> Hi Andreas-
>
> Thanks for this work! I agree with Leonard concerning the changes to
> lib/canonical/database/revision.py - I think it would be best to just revert
> both changes in there. Yes, you're removing a line, but we generally don't
> make whitespace changes to a file unless we actually edit it so that we don't
> cause spurious conflicts. Other than that, thanks for looking into this!

I've re-added the blankline at the end of the file too. Now everything should be fine, thanks!

Revision history for this message
Tom Haddon (mthaddon) wrote :

> Thanks for doing this branch. It looks like a good first step.
>
> I'm very suspicious of the unconditional return statement in line 51. It looks
> like you added that during development and that it should be removed.
>
> Other than that, this branch looks good. Approved*. I'm a trainee reviewer so
> you'll need to get rockstar to approve my change, and then have an admin look
> at it because it changes configuration.

I've checked the production-configs branch and we don't set this value, so I think it's safe to change it.

Thanks for checking with us, that's definitely needed for any config change.

review: Approve
Revision history for this message
Leonard Richardson (leonardr) wrote :

Unfortunately this branch caused some test failure when I ran the full test suite.

Failure in test lib/lp/bugs/tests/../stories/bugattachments/xx-display-filesize-attachment.txt
Failed doctest test for xx-display-filesize-attachment.txt
  File "lib/lp/bugs/tests/../stories/bugattachments/xx-display-filesize-attachment.txt", line 0

----------------------------------------------------------------------
File "lib/lp/bugs/tests/../stories/bugattachments/xx-display-filesize-attachment.txt", line 48, in xx-display-filesize-attachment.txt
Failed example:
    user_browser.url
Differences (ndiff with -expected +actual):
    - 'http://bugs.launchpad.dev/firefox/+bug/1'
    + 'http://bugs.launchpad.dev/firefox/+bug/1/+addcomment'
    ? ++++++++++++
----------------------------------------------------------------------
File "lib/lp/bugs/tests/../stories/bugattachments/xx-display-filesize-attachment.txt", line 51, in xx-display-filesize-attachment.txt
Failed example:
    last_comment = find_tags_by_class(
        user_browser.contents, 'boardCommentBody')[-1]
Exception raised:
    Traceback (most recent call last):
      File "/var/launchpad/test/lib/zope/testing/doctest.py", line 1360, in __run
        compileflags, 1) in test.globs
      File "<doctest xx-display-filesize-attachment.txt[23]>", line 1, in ?
    IndexError: list index out of range
----------------------------------------------------------------------
File "lib/lp/bugs/tests/../stories/bugattachments/xx-display-filesize-attachment.txt", line 54, in xx-display-filesize-attachment.txt
Failed example:
    for attachment in last_comment('li', {'class': 'download'}):
        print extract_text(attachment)
Differences (ndiff with -expected +actual):
      description text
    - (2.6 KiB, text/plain)
    + (270 bytes,
    + text/plain)

I don't know exactly what's going on here, but the test that fails does have a connection to this code, so I doubt it's a spurious failure. Try to get it to work and let me know if you have problems.

Revision history for this message
Andrea Corbellini (andrea.corbellini) wrote :

> I don't know exactly what's going on here, but the test that fails does have a
> connection to this code, so I doubt it's a spurious failure. Try to get it to
> work and let me know if you have problems.

Argh! For some reasons I haven't seen xx-display-filesize-attachment.txt in the output of grep. Now it's fixed, and works as expected.

Sorry for this! I hope this won't happen again.

Revision history for this message
Leonard Richardson (leonardr) wrote :

I've reviewed your change and it looks good. rockstar needs to mentor the change, and I'm running the test suite again to verify that there are no failures.

review: Approve
Revision history for this message
Paul Hummer (rockstar) wrote :

> > I don't know exactly what's going on here, but the test that fails does have
> a
> > connection to this code, so I doubt it's a spurious failure. Try to get it
> to
> > work and let me know if you have problems.
>
> Argh! For some reasons I haven't seen xx-display-filesize-attachment.txt in
> the output of grep. Now it's fixed, and works as expected.
>
> Sorry for this! I hope this won't happen again.

It's not a big deal. This happens in more cases than you'd think, and it's the entire reason we land things through ec2test.

In the future, when you make incremental changes, it's good to post the incremental diff. That way, I don't have to grab your branch to see the changes you've made. I've learned that in Launchpad development, the best thing you can do is make your reviewer's job easy. :)

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'configs/development/launchpad-lazr.conf'
--- configs/development/launchpad-lazr.conf 2009-07-29 09:46:46 +0000
+++ configs/development/launchpad-lazr.conf 2009-07-29 18:53:51 +0000
@@ -119,7 +119,7 @@
119[launchpad]119[launchpad]
120code_domain: code.launchpad.dev120code_domain: code.launchpad.dev
121default_batch_size: 5121default_batch_size: 5
122max_bug_attachment_size: 2097152122max_attachment_size: 2097152
123branchlisting_batch_size: 6123branchlisting_batch_size: 6
124openid_preauthorization_acl:124openid_preauthorization_acl:
125 localhost http://launchpad.dev/125 localhost http://launchpad.dev/
126126
=== modified file 'configs/testrunner/launchpad-lazr.conf'
--- configs/testrunner/launchpad-lazr.conf 2009-07-24 11:59:49 +0000
+++ configs/testrunner/launchpad-lazr.conf 2009-07-29 18:53:51 +0000
@@ -121,7 +121,7 @@
121max_scaling: 2121max_scaling: 2
122122
123[launchpad]123[launchpad]
124max_bug_attachment_size: 1024124max_attachment_size: 1024
125bzr_imports_root_url: http://localhost:10899125bzr_imports_root_url: http://localhost:10899
126geoip_database: /usr/share/GeoIP/GeoLiteCity.dat126geoip_database: /usr/share/GeoIP/GeoLiteCity.dat
127127
128128
=== modified file 'lib/canonical/config/schema-lazr.conf'
--- lib/canonical/config/schema-lazr.conf 2009-07-29 09:46:46 +0000
+++ lib/canonical/config/schema-lazr.conf 2009-07-29 18:53:51 +0000
@@ -950,10 +950,10 @@
950# datatype: integer950# datatype: integer
951max_batch_size: 300951max_batch_size: 300
952952
953# Maximum size of bug attachments in bytes. A value of 0 means953# Maximum size of attachments in bytes. A value of 0 means
954# no limit.954# no limit.
955# datatype: integer955# datatype: integer
956max_bug_attachment_size: 0956max_attachment_size: 0
957957
958# Email address, to which all error reports are sent.958# Email address, to which all error reports are sent.
959# Messages should have distinct Subject: or Keywords: headers959# Messages should have distinct Subject: or Keywords: headers
960960
=== modified file 'lib/canonical/database/revision.py'
--- lib/canonical/database/revision.py 2009-06-25 05:30:52 +0000
+++ lib/canonical/database/revision.py 2009-07-29 18:53:51 +0000
@@ -51,6 +51,7 @@
51 (major, minor, patch) for major, minor, patch in cur.fetchall()51 (major, minor, patch) for major, minor, patch in cur.fetchall()
52 if major >= fs_major52 if major >= fs_major
53 ]53 ]
54 return
5455
55 # Raise an exception if we have a patch on the filesystem that has not56 # Raise an exception if we have a patch on the filesystem that has not
56 # been applied to the database.57 # been applied to the database.
@@ -86,4 +87,3 @@
86 confirm_dbrevision(cur)87 confirm_dbrevision(cur)
87 finally:88 finally:
88 con.close()89 con.close()
89
9090
=== renamed file 'lib/canonical/launchpad/validators/bugattachment.py' => 'lib/canonical/launchpad/validators/attachment.py'
--- lib/canonical/launchpad/validators/bugattachment.py 2009-06-25 05:30:52 +0000
+++ lib/canonical/launchpad/validators/attachment.py 2009-07-29 18:24:34 +0000
@@ -1,21 +1,21 @@
1# Copyright 2009 Canonical Ltd. This software is licensed under the1# Copyright 2009 Canonical Ltd. This software is licensed under the
2# GNU Affero General Public License version 3 (see the file LICENSE).2# GNU Affero General Public License version 3 (see the file LICENSE).
33
4"""Validators for bug attachments."""4"""Validators for attachments."""
55
6__metaclass__ = type6__metaclass__ = type
7__all__ = ['bug_attachment_size_constraint']7__all__ = ['attachment_size_constraint']
88
9from canonical.config import config9from canonical.config import config
10from canonical.launchpad.validators import LaunchpadValidationError10from canonical.launchpad.validators import LaunchpadValidationError
1111
12def bug_attachment_size_constraint(value):12def attachment_size_constraint(value):
13 """Constraint for a bug attachment's file size.13 """Constraint for an attachment's file size.
1414
15 The file is not allowed to be empty.15 The file is not allowed to be empty.
16 """16 """
17 size = len(value)17 size = len(value)
18 max_size = config.launchpad.max_bug_attachment_size18 max_size = config.launchpad.max_attachment_size
19 if size == 0:19 if size == 0:
20 raise LaunchpadValidationError(u'Cannot upload empty file.')20 raise LaunchpadValidationError(u'Cannot upload empty file.')
21 elif max_size > 0 and size > max_size:21 elif max_size > 0 and size > max_size:
@@ -23,4 +23,3 @@
23 u'Cannot upload files larger than %i bytes' % max_size)23 u'Cannot upload files larger than %i bytes' % max_size)
24 else:24 else:
25 return True25 return True
26
2726
=== modified file 'lib/lp/bugs/doc/bugattachments.txt'
--- lib/lp/bugs/doc/bugattachments.txt 2009-07-06 17:55:29 +0000
+++ lib/lp/bugs/doc/bugattachments.txt 2009-07-29 18:53:51 +0000
@@ -143,7 +143,7 @@
143 u'Cannot upload empty file.'143 u'Cannot upload empty file.'
144144
145It's possible to limit the maximum size of the attachments by setting145It's possible to limit the maximum size of the attachments by setting
146max_bug_attachment_size in launchpad.conf. The default value for the146max_attachment_size in launchpad.conf. The default value for the
147testrunner is 1024, so let's create a file larger than that and try to147testrunner is 1024, so let's create a file larger than that and try to
148upload it:148upload it:
149149
@@ -170,11 +170,11 @@
170means no limit:170means no limit:
171171
172 >>> from canonical.config import config172 >>> from canonical.config import config
173 >>> max_bug_attachment_size = """173 >>> max_attachment_size = """
174 ... [launchpad]174 ... [launchpad]
175 ... max_bug_attachment_size: 0175 ... max_attachment_size: 0
176 ... """176 ... """
177 >>> config.push('max_bug_attachment_size', max_bug_attachment_size)177 >>> config.push('max_attachment_size', max_attachment_size)
178 >>> add_request = LaunchpadTestRequest(178 >>> add_request = LaunchpadTestRequest(
179 ... method="POST",179 ... method="POST",
180 ... form={'field.subject': u'Title',180 ... form={'field.subject': u'Title',
@@ -287,7 +287,7 @@
287 >>> bug_one.attachments[-1].libraryfile.http_url287 >>> bug_one.attachments[-1].libraryfile.http_url
288 'http://.../foo-bar-baz'288 'http://.../foo-bar-baz'
289289
290 >>> config_data = config.pop('max_bug_attachment_size')290 >>> config_data = config.pop('max_attachment_size')
291 >>> event_listener.unregister()291 >>> event_listener.unregister()
292292
293293
@@ -463,7 +463,3 @@
463 >>> print latest_notification.message.text_contents463 >>> print latest_notification.message.text_contents
464 ** Attachment removed: "Attachment to be deleted"464 ** Attachment removed: "Attachment to be deleted"
465 http://.../foo.baz465 http://.../foo.baz
466
467
468
469
470466
=== modified file 'lib/lp/bugs/interfaces/bug.py'
--- lib/lp/bugs/interfaces/bug.py 2009-07-27 18:22:07 +0000
+++ lib/lp/bugs/interfaces/bug.py 2009-07-29 18:53:51 +0000
@@ -44,8 +44,8 @@
44from lp.registry.interfaces.mentoringoffer import ICanBeMentored44from lp.registry.interfaces.mentoringoffer import ICanBeMentored
45from lp.registry.interfaces.person import IPerson45from lp.registry.interfaces.person import IPerson
46from canonical.launchpad.validators.name import name_validator46from canonical.launchpad.validators.name import name_validator
47from canonical.launchpad.validators.bugattachment import (47from canonical.launchpad.validators.attachment import (
48 bug_attachment_size_constraint)48 attachment_size_constraint)
4949
50from lazr.restful.declarations import (50from lazr.restful.declarations import (
51 REQUEST_USER, call_with, export_as_webservice_entry,51 REQUEST_USER, call_with, export_as_webservice_entry,
@@ -456,7 +456,7 @@
456456
457 @call_with(owner=REQUEST_USER)457 @call_with(owner=REQUEST_USER)
458 @operation_parameters(458 @operation_parameters(
459 data=Bytes(constraint=bug_attachment_size_constraint),459 data=Bytes(constraint=attachment_size_constraint),
460 comment=Text(), filename=TextLine(), is_patch=Bool(),460 comment=Text(), filename=TextLine(), is_patch=Bool(),
461 content_type=TextLine(), description=Text())461 content_type=TextLine(), description=Text())
462 @export_factory_operation(IBugAttachment, [])462 @export_factory_operation(IBugAttachment, [])
@@ -607,7 +607,7 @@
607 :status: The status the bugtask should be set to.607 :status: The status the bugtask should be set to.
608 :user: The `IPerson` doing the change.608 :user: The `IPerson` doing the change.
609609
610 If a bug task was edited, emit a 610 If a bug task was edited, emit a
611 `lazr.lifecycle.interfaces.IObjectModifiedEvent` and611 `lazr.lifecycle.interfaces.IObjectModifiedEvent` and
612 return the edited bugtask.612 return the edited bugtask.
613613
@@ -796,7 +796,7 @@
796 vocabulary="Bug")796 vocabulary="Bug")
797 filecontent = Bytes(797 filecontent = Bytes(
798 title=u"Attachment", required=False,798 title=u"Attachment", required=False,
799 constraint=bug_attachment_size_constraint)799 constraint=attachment_size_constraint)
800 patch = Bool(title=u"This attachment is a patch", required=False,800 patch = Bool(title=u"This attachment is a patch", required=False,
801 default=False)801 default=False)
802 attachment_description = Title(title=u'Description', required=False)802 attachment_description = Title(title=u'Description', required=False)
803803
=== modified file 'lib/lp/bugs/interfaces/bugmessage.py'
--- lib/lp/bugs/interfaces/bugmessage.py 2009-06-25 00:40:31 +0000
+++ lib/lp/bugs/interfaces/bugmessage.py 2009-07-29 18:53:51 +0000
@@ -21,8 +21,8 @@
21from lp.bugs.interfaces.bugwatch import IBugWatch21from lp.bugs.interfaces.bugwatch import IBugWatch
22from canonical.launchpad.interfaces.launchpad import IHasBug22from canonical.launchpad.interfaces.launchpad import IHasBug
23from canonical.launchpad.interfaces.message import IMessage23from canonical.launchpad.interfaces.message import IMessage
24from canonical.launchpad.validators.bugattachment import (24from canonical.launchpad.validators.attachment import (
25 bug_attachment_size_constraint)25 attachment_size_constraint)
2626
2727
28class IBugMessage(IHasBug):28class IBugMessage(IHasBug):
@@ -80,7 +80,7 @@
80 comment = Text(title=u"Comment", required=False)80 comment = Text(title=u"Comment", required=False)
81 filecontent = Bytes(81 filecontent = Bytes(
82 title=u"Attachment", required=False,82 title=u"Attachment", required=False,
83 constraint=bug_attachment_size_constraint)83 constraint=attachment_size_constraint)
84 patch = Bool(title=u"This attachment is a patch", required=False,84 patch = Bool(title=u"This attachment is a patch", required=False,
85 default=False)85 default=False)
86 attachment_description = Title(title=u'Description', required=False)86 attachment_description = Title(title=u'Description', required=False)
8787
=== modified file 'lib/lp/bugs/stories/bugs/xx-bug-comment-attach-file.txt'
--- lib/lp/bugs/stories/bugs/xx-bug-comment-attach-file.txt 2009-06-12 16:36:02 +0000
+++ lib/lp/bugs/stories/bugs/xx-bug-comment-attach-file.txt 2009-07-29 18:53:51 +0000
@@ -69,12 +69,12 @@
69 There is 1 error.69 There is 1 error.
70 Cannot upload empty file.70 Cannot upload empty file.
7171
72The size of uploaded files is limited with the max_bug_attachment_size72The size of uploaded files is limited with the max_attachment_size
73option in launchpad.conf. In our example, the size is limited to 1024.73option in launchpad.conf. In our example, the size is limited to 1024.
7474
75 >>> from canonical.config import config75 >>> from canonical.config import config
7676
77 >>> print config.launchpad.max_bug_attachment_size77 >>> print config.launchpad.max_attachment_size
78 102478 1024
7979
80 >>> user_browser.open(80 >>> user_browser.open(