Ticket #1641 (closed defect: fixed)
pagination fails whe 0 rows returned
| Reported by: | ondrejj | Owned by: | anonymous |
|---|---|---|---|
| Priority: | normal | Milestone: | 1.0.4 |
| Component: | TurboGears | Version: | 1.0.4b3 |
| Severity: | normal | Keywords: | paginate |
| Cc: |
Description
Page handler: <function _wrapper at 0xa86609c> Traceback (most recent call last):
File "/usr/lib/python2.5/site-packages/cherrypy/_cphttptools.py", line 105, in _run
self.main()
File "/usr/lib/python2.5/site-packages/cherrypy/_cphttptools.py", line 254, in main
body = page_handler(*virtual_path, self.params)
File "/home/ondrejj/tmp/python/TurboGears-1.0.4b3-py2.5.egg/turbogears/identity/conditions.py", line 275, in _wrapper
return fn( *args, kw )
File "<string>", line 3, in index File "/home/ondrejj/tmp/python/TurboGears-1.0.4b3-py2.5.egg/turbogears/controllers.py", line 344, in expose
*args, kw)
File "<string>", line 5, in run_with_transaction File "/home/ondrejj/tmp/python/TurboGears-1.0.4b3-py2.5.egg/turbogears/database.py", line 406, in sa_rwt
retval = func(*args, kw)
File "<string>", line 5, in _expose File "/home/ondrejj/tmp/python/TurboGears-1.0.4b3-py2.5.egg/turbogears/controllers.py", line 359, in <lambda>
mapping, fragment, args, kw)))
File "/home/ondrejj/tmp/python/TurboGears-1.0.4b3-py2.5.egg/turbogears/controllers.py", line 386, in _execute_func
output = errorhandling.try_call(func, *args, kw)
File "/home/ondrejj/tmp/python/TurboGears-1.0.4b3-py2.5.egg/turbogears/errorhandling.py", line 72, in try_call
return func(self, *args, kw)
File "<string>", line 3, in index File "/home/ondrejj/tmp/python/TurboGears-1.0.4b3-py2.5.egg/turbogears/paginate.py", line 203, in decorated
page_count = int(ceil(float(row_count)/limit_))
TypeError?: float() argument must be a string or a number
When no results returned row_count may be "None" and this row fails. I suggest to update this row at least this way:
page_count = int(ceil(float(row_count or 0)/limit_))
Change History
comment:2 follow-up: ↓ 3 Changed 4 years ago by ondrejj
It's problematic to create a simple application for you.
May be generated SELECT may be helpful for you:
SELECT count(ip.id) FROM device LEFT OUTER JOIN ip ON ip.device = device.id LEFT OUTER JOIN domain ON domain.id = ip.domain JOIN tg_group ON tg_group.group_id = device.grp JOIN user ON user.id = device.owner WHERE device.grp = tg_group.group_id AND ip.name LIKE %s AND device.grp IN (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s) GROUP BY device.id ['kjshdfkjsg%', 1L, 2L, 3L, 4L, 5L, 6L, 7L, 8L, 9L, 10L, 11L, 12L, 13L] None
It's return value is None, when the GROUP BY clausule is present. I am using SQLAlchemy 0.4.1 and MySQL-5.0.45. Working well with turbogears 1.0.3.2 without my patch and also working well with turbogears 1.0.4b3 with my patch. It's also possible to change this line: row_count = var_data.count() or 0 When var_data.count() is zero, this zero will be replaced by zero after "or". When it is None, it is corrected to "0". When is is a non-zero value, it is leaved unchanged.
Do you really need an example code? Can I provide other information?
comment:3 in reply to: ↑ 2 Changed 4 years ago by roger.demetrescu
- Status changed from new to closed
- Resolution set to fixed
Hei ondrejj -
Can you provide us an example code/app which makes row_count return None instead of 0 ?
Thanks,
Roger