# Re: [Zope-dev] Bug in ZTUtil.Batch solved

Please post this in the Collector at http://zope.org/Collectors/Zope

jens

On Mar 22, 2004, at 7:09, AP Meyer wrote:

Hi Zopers

It seems that there is a bug in ZTUtil.Batch: when the batch should be the length of the batch and there are exactly as many orphans as there would fit on one page the length of the batch becomes size instead of size+orphans.

Here are the numbers:

```no of
batches    start    end    orphan    length    sequence_length
1          1        12     3         12        12
1          1        10     3         10        13      <<< WRONG *
2          1        10     3         10        14

```

* end and length should be 13 in this case, 3 items are omitted

```        length=12       length=13       length=14
1               1               1
2               2               2
3               3               3
4               4               4
5               5               5
6               6               6
7               7               7
8               8               8
9               9               9
10              10              10
11                              11 | second batch
12                              12 |
13 |
14 |```

So, there is a jump on the edge where there should be one batch of the length sequence_length == length+orphans. At that point 3 (in the above case) items disappear.
I have looked at the code in ZTUtils.Batch.py and found the following solution (line 109):

94 def opt(start,end,size,orphan,sequence):
95 if size < 1:
96 if start > 0 and end > 0 and end >= start:
97 size=end+1-start
98 else: size=7
99
100 if start > 0:
101
102 try: sequence[start-1]
103 except IndexError: start=len(sequence)
104
105 if end > 0:
106 if end < start: end=start
107 else:
108 end=start+size-1
109 #try: sequence[end+orphan-1]
110 try: sequence[end+orphan] # replace above with this
111 except IndexError: end=len(sequence)
112 ...

Can somebody confirm that this solution is correct and modify it in the CVS, please?

NB This has been run in Zope 2.7 with Python 2.3.3.

```thanks
Andre```

-- ----------------------------------------------------------------------- -------
The disclaimer that applies to e-mail from
TNO Physics and Electronics Laboratory
can be found on: http://www.tno.nl/disclaimer/email.html
----------------------------------------------------------------------- -------

```_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists - http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )
```

smime.p7s
Description: S/MIME cryptographic signature

```_______________________________________________
Zope-Dev maillist  -  [EMAIL PROTECTED]
http://mail.zope.org/mailman/listinfo/zope-dev
**  No cross posts or HTML encoding!  **
(Related lists -
http://mail.zope.org/mailman/listinfo/zope-announce
http://mail.zope.org/mailman/listinfo/zope )
```