Warning: Can't synchronize with repository "(default)" (Unsupported version control system "svn": No module named svn). Look in the Trac log for more information.

Ticket #1641 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

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


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


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:1 Changed 12 years ago by roger.demetrescu

Hei ondrejj -

Can you provide us an example code/app which makes row_count return None instead of 0 ?



comment:2 follow-up: ↓ 3 Changed 12 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 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 12 years ago by roger.demetrescu

  • Status changed from new to closed
  • Resolution set to fixed

Replying to ondrejj:

Do you really need an example code? Can I provide other information?

The "group by" hint was enough to me. :)

I wanted to reproduce this error in a unit test before applying your patch.

Fixed in r3845 and r3846.

Thanks !!

comment:4 Changed 12 years ago by ondrejj

Thank you.

Please change my name in contributors section, prefferably to: Jan ONDREJ (SAL)

comment:5 Changed 12 years ago by roger.demetrescu

Done at r3847 and r3848. :)

Note: See TracTickets for help on using tickets.