bug in paginate decorator

1 view
Skip to first unread message

Jose Soares

unread,
Apr 16, 2007, 11:28:38 AM4/16/07
to turbo...@googlegroups.com
Hi,

In the sql_get_column function at line 248 the getattr looks for the
field name in the table object, in this way
the SASelectResults based on mappers using column_prefix don't find the
attribute 'colname'.
I have to modified it as follow...


243 def sql_get_column(colname, var_data):
244 """Return a column from var_data based on colname."""
245 if isinstance(var_data, SelectResults):
246 col = getattr(var_data.sourceClass.q, colname, None)
247 elif isinstance(var_data, SASelectResults):
248 #col = getattr(var_data._query.table.c, colname, None)
249 col = getattr(var_data._query.mapper.c,
colname[len(var_data._query.mapper.column_prefix or ''):], None)
250 else:
251 raise StandardError, 'expected SelectResults'
252 return col

what about have this change in the official version?

jo

Jorge Vargas

unread,
Apr 17, 2007, 10:13:58 AM4/17/07
to turbo...@googlegroups.com
could you open a ticket for that with the proper patch?
> jo
>
>
> >
>

Jose Soares

unread,
Apr 18, 2007, 6:06:25 AM4/18/07
to turbo...@googlegroups.com
Jorge Vargas ha scritto:
I opened the ticket #1360 and I added the proper patch
see it at http://trac.turbogears.org/ticket/1360

I hope I did it right, because it was the first time I used trac. :-\

jo


>> jo
>>
>>
>>
>
> >
>

Jorge Vargas

unread,
Apr 18, 2007, 11:44:30 AM4/18/07
to turbo...@googlegroups.com
Could someone using SA check that out it seems a bit hackish to me :)

> I hope I did it right, because it was the first time I used trac. :-\
>

close to check out :)
http://docs.turbogears.org/patching_guidelines

> jo
>
>
> >> jo
> >>
> >>
> >>
> >
> > >
> >
>
>
> >
>

Chris Miles

unread,
Apr 24, 2007, 10:10:17 AM4/24/07
to TurboGears
On Apr 18, 4:44 pm, "Jorge Vargas" <jorge.var...@gmail.com> wrote:
> > I opened the ticket #1360 and I added the proper patch
> > see it at http://trac.turbogears.org/ticket/1360
>
> Could someone using SA check that out it seems a bit hackish to me :)

I've tested this change and it doesn't break the "normal" case. I
mean "normal" case as when not using column_prefix with the mappers.

I've never actually used column_prefix, but if I add a column_prefix
to my assign_mapper() call and test this change it actually fails.
colname is still being passed through as the table name (ie: not
prefixed). Without the patch is actually works. It is possible that
I am not using the column_prefix correctly.

I'd suggest showing an example that breaks without the patch so we can
more clearly see what case it is fixing.

Cheers,
Chris

jose

unread,
Apr 25, 2007, 9:09:46 AM4/25/07
to turbo...@googlegroups.com
Chris Miles wrote:

create and populate this table in PostgreSQL...

CREATE TABLE person (
name text NOT NULL primary key,
age integer
);

COPY person (name, age) FROM stdin;
paul 18
john 13
mary 12
carol 14
\.

using the attached file to view data...

here the error message:

500 Internal error


The server encountered an unexpected condition which prevented it from
fulfilling the request.

Page handler: <bound method Root.index of <pagetest.controllers.Root
object at 0xb72109ec>>
Traceback (most recent call last):
File
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
line 105, in _run
self.main()
File
"/usr/lib/python2.4/site-packages/CherryPy-2.2.1-py2.4.egg/cherrypy/_cphttptools.py",
line 254, in main
body = page_handler(*virtual_path, **self.params)
File "<string>", line 3, in index
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py",
line 334, in expose
output = database.run_with_transaction(
File "<string>", line 5, in run_with_transaction
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/database.py",
line 352, in sa_rwt
retval = dispatch_exception(e,args,kw)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/database.py",
line 341, in sa_rwt
retval = func(*args, **kw)
File "<string>", line 5, in _expose
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py",
line 351, in <lambda>
mapping, fragment, args, kw)))
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/controllers.py",
line 378, in _execute_func
output = errorhandling.try_call(func, *args, **kw)
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/errorhandling.py",
line 73, in try_call
return func(self, *args, **kw)
File "<string>", line 3, in index
File
"/usr/lib/python2.4/site-packages/TurboGears-1.0.1-py2.4.egg/turbogears/paginate.py",
line 75, in decorated
raise StandardError, "The order column (%s) doesn't exist" % colname
StandardError: The order column (prefix__age) doesn't exist

-----------------

and now apply the patch at http://trac.turbogears.org/ticket/1360

and now it should work... :-)

jo

page.tgz

Chris Miles

unread,
Apr 25, 2007, 10:34:25 AM4/25/07
to TurboGears

On Apr 25, 2:09 pm, jose <j...@sferacarta.com> wrote:
> and now apply the patch athttp://trac.turbogears.org/ticket/1360


>
> and now it should work... :-)

Agreed.

I can't help but think there's a nicer (more SQLAlchemy-friendly) way
to implement the orderby part of paginate, but I can't think of one
yet as I'm hitting my limits of SA knowledge.

Cheers,
Chris

Reply all
Reply to author
Forward
0 new messages