Merge lp:~jtv/lazr.batchnavigator/bug-574159 into lp:lazr.batchnavigator
| Status: | Merged |
|---|---|
| Approved by: | Jeroen T. Vermeulen on 2010-05-07 |
| Approved revision: | 30 |
| Merged at revision: | 28 |
| Proposed branch: | lp:~jtv/lazr.batchnavigator/bug-574159 |
| Merge into: | lp:lazr.batchnavigator |
| Diff against target: |
101 lines (+55/-14) 2 files modified
src/lazr/batchnavigator/README.txt (+21/-0) src/lazr/batchnavigator/_batchnavigator.py (+34/-14) |
| To merge this branch: | bzr merge lp:~jtv/lazr.batchnavigator/bug-574159 |
| Related bugs: |
| Reviewer | Review Type | Date Requested | Status |
|---|---|---|---|
| Abel Deuring (community) | code | Approve on 2010-05-07 | |
| Barry Warsaw | code | 2010-05-03 | Pending |
|
Review via email:
|
|||
Commit Message
Ignore negative batch sizes.
Description of the Change
= Bug 574159 =
The batch navigator happily accepts negative batch sizes, which as far as I can tell have no meaning and cause oopses in Launchpad.
Here's a fix to make it ignore negative batch sizes. If we ever do decide to assign a useful meaning to negative batch sizes, at least this makes the choice explicit and tests it.
At least, that's the theory. The fact is that I haven't figured out how to run the test yet.
| Jeroen T. Vermeulen (jtv) wrote : | # |
| Barry Warsaw (barry) wrote : | # |
> Had to patch up the test a bit, but it's passing now.
Well the branch diff /still/ isn't available on the page, but I managed to
trick Launchpad into giving it to me.
=== modified file 'src/lazr/
--- src/lazr/
+++ src/lazr/
> @@ -191,6 +191,20 @@
> >>> navigator.
> 'http://
>
> +The batch argument must be positive. Negative numbers or zero are ignored.
> +
> + >>> from cgi import parse_qs
> + >>> BatchNavigator(
> + >>> next_batch = reindeer_
> + >>> print parse_qs(
> + 50
> +
> + >>> BatchNavigator(
> + >>> next_batch = reindeer_
> + >>> print parse_qs(
> + 50
I'm not sure how this shows that the batch is ignored. Without looking at the
rest of the test, what does '50' mean? Maybe the docs before this explain
that this is the default batch size, but if not, could you provide a little
more context?
> +
> +
> =============
> Empty Batches
> =============
=== modified file 'src/lazr/
--- src/lazr/
+++ src/lazr/
> @@ -108,16 +108,19 @@
> self.default_size = size
>
> request_size = batch_params_
> - if request_size:
> + if request_size is not None:
> try:
> - size = int(request_size)
> + request_size = int(request_size)
I don't love the fact that you're changing the type of the local variable
`request_size` within the conditional. Are you sure request_size isn't used
or referenced outside of this block?
> except (ValueError, TypeError):
> - pass
> - if size > self.max_
> + request_size = 0
> +
> + if request_size > self.max_
> raise InvalidBatchSiz
> 'Maximum for "%s" parameter is %d.' %
> (self.batch_
> self.max_
> + if request_size > 0:
> + size = request_size
No InvalidBatchSiz
makes more sense?
>
> if size is None:
> size = self.default_
- 30. By Jeroen T. Vermeulen on 2010-05-05
-
Extracted method.
| Jeroen T. Vermeulen (jtv) wrote : | # |
Hi Barry,
Thanks for looking at it despite the difficulties.
> Well the branch diff /still/ isn't available on the page, but I managed to
> trick Launchpad into giving it to me.
Unfortunately you still got an outdated diff. Meanwhile I've updated it again; it's probably best to do this using bzr.
> === modified file 'src/lazr/
> --- src/lazr/
> +++ src/lazr/
> > @@ -191,6 +191,20 @@
> > >>> navigator.
> > 'http://
> >
> > +The batch argument must be positive. Negative numbers or zero are ignored.
> > +
> > + >>> from cgi import parse_qs
> > + >>> BatchNavigator(
> > + >>> next_batch = reindeer_
> > + >>> print parse_qs(
> > + 50
> > +
> > + >>> BatchNavigator(
> > + >>> next_batch = reindeer_
> > + >>> print parse_qs(
> > + 50
>
> I'm not sure how this shows that the batch is ignored. Without looking at the
> rest of the test, what does '50' mean? Maybe the docs before this explain
> that this is the default batch size, but if not, could you provide a little
> more context?
This is where the outdated diff hurts us. I had changed the test to state that the default batch size was used instead, and show the default batch size (which is 50) before showing that the actual batch sizes for these two batch navigators are also 50.
> === modified file 'src/lazr/
> --- src/lazr/
> +++ src/lazr/
> > @@ -108,16 +108,19 @@
> > self.default_size = size
> >
> > request_size = batch_params_
> None)
> > - if request_size:
> > + if request_size is not None:
> > try:
> > - size = int(request_size)
> > + request_size = int(request_size)
>
> I don't love the fact that you're changing the type of the local variable
> `request_size` within the conditional. Are you sure request_size isn't used
> or referenced outside of this block?
Quite. I've now done the right thing though: extracted the method and used separate names for the variables. It also makes the logic a bit easier to follow, because the new method can just "return None" whenever things don't work out.
> > except (ValueError, TypeError):
> > - pass
> > - if size > self.max_
> > + request_size = 0
> > +
> > + if request_size > self.max_
> > raise InvalidBatchSiz
> > 'Maximum for "%s" parameter is %d.' %
> > (self.batch_
> > self.max_
> > + if request_size > 0:
> > + siz...
| Jeroen T. Vermeulen (jtv) wrote : | # |
The diff updated promptly this time.

Had to patch up the test a bit, but it's passing now.