From: Hendrik Mans <hendrik@ma...> - 2004-03-26 09:10:37
>>> from Crop.Data.User import User
>>> u1 = User.get(1)
>>> u2 = User.get('1')
>>> u1 == u2
Is this by design? I was expecting SQLObject to either return the same
object instance *or* raise an exception when passing the string.
Background: I'm currently using SQLObject with CherryPy (a Python web
application framework, http://www.cherrypy.org). CherryPy receives GET/POST
parameters as strings, so when I want to use them to fetch an SQLObject, I
have to convert them to ints first:
u = User.get(int(id))
It's not much of a problem, but it's really hard to miss, since SQLObject
simply returns a different object representing the same data.
The User class is a simple SQLObject derived class with no "funky"
Currently using SQLObject from SVN, revision 79.
From: Ian Bicking <ianb@co...> - 2004-03-27 04:59:12
On Mar 26, 2004, at 3:41 AM, Hendrik Mans wrote:
> Hello everyone,
>>>> from Crop.Data.User import User
>>>> u1 = User.get(1)
>>>> u2 = User.get('1')
>>>> u1 == u2
> Is this by design? I was expecting SQLObject to either return the same
> object instance *or* raise an exception when passing the string.
Well... not design. I guess it's a known problem, though I had
forgotten about it for a while. If you do something like:
def _init(self, id, connection=None):
id = int(id)
return SQLObject._init(self, id, connection=connection)
I believe that should resolve it for you. Ultimately the id type
should become part of a column specifier, like other columns are
specified, but there's some other issues involved with that that I
haven't gotten around to.
Ian Bicking | ianb@... | http://blog.ianbicking.org
Get latest updates about Open Source Projects, Conferences and News.