Re: [SQLObject] Problems with str() on SQLObjects
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
|
From: Ian B. <ia...@co...> - 2003-05-10 21:23:39
|
On Sat, 2003-05-10 at 09:57, Simen Brekken wrote:
> Where Entry is an SQLObject:
>
> -- BEGIN entry.py --
> class Entry(SQLObject):
> _columns = [IntCol('date', default=None), Col('content',
> default=None),
> IntCol('mood', default=5)]
> _connection = SQLiteConnection('C:/Home/Projects/blog/blog.db',
> debug=1)
>
> def content(self):
> return {'date': self.date, 'content': self.content, 'mood':
> self.mood}
> -- END entry.py --
This is where your bug is -- your content definition overrides your
content column. So when you do a repr, it tries to construct:
<Entry (self.id) date=(self.date) content=(self.content)
mood=(self.mood)> [substituting (self.xxx), of course)
Because you redefined it, self.content is now a method. Methods' repr
is <bound method (method name) of (repr(object-method-is-bound-to)>. So
we get an infinite loop.
Obviously the resulting loop is not a very good indication of the
underlying problem. I'm not sure what the best resolution is -- maybe
SQLObject should make sure that there isn't a method shadowing any
column, since I don't think there's any reason you'd want to do that.
In this case you should rename the content() method to perhaps
_get_allContent() or something.
Ian
|