[SQLObject] how to test possible with sqlmeta fromDatabase?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Stewart M. <ste...@gm...> - 2005-12-14 17:06:06
|
I've discovered a peculiar behaviour in my web app, having to do with sqlmeta class and fromDatabase =3D True All in well in my app when I defined all of 7 my tables using SQLObject class instances, e.g. 119 class Admin(SQLObject): 120 =09 """this corresponds to the 'admin' table in MySQL""" 121 =09 _connection =3D conn 122 =09 #id =3D IntCol() 123 =09 pageviews =3D IntCol(default =3D 1) Recently I decided that instead of explicitly creating these objects, I should let SQLObject do the work of determining each table object's attributes by having it inspect the MySQL database. So I altered my Admin definition to the following: class Admin(SQLObject): class sqlmeta: fromDatabase =3D True _connection =3D conn When I do this, all of my database objects from my 7 tables are successfully created, with one sole exception. In the Admin table, the pageviews attribute is not created. And yet obviously the field exists in the database: mysql> select * from admin where id=3D1; +----+-----------+ | id | pageviews | +----+-----------+ | 1 | 1055 | +----+-----------+ Here's the failure in SQLObject: >>> from objects import Admin >>> rec =3D Admin.get(1) 1/QueryOne: SELECT NULL FROM admin WHERE id =3D 1 >>> rec <Admin 1 > >>> rec.pageviews Traceback (most recent call last): File "<stdin>", line 1, in ? AttributeError: 'Admin' object has no attribute 'pageviews' Where can I look in the code to find where the attribute creation is failing? In which module are the objects created? I could just go back to defining the objects explicitly, I know, but I'd like to try to solve this problem, and to know whether it's in my code or in SQLObject. Addendum: Here's the full error listing from my browser: Unrecoverable error in the server. =3D=3D=3DFirst Error=3D=3D=3D Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 88, in _run self.main() File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 233, in main body =3D page_handler(*virtual_path, **self.paramMap) File "test.py", line 34, in index return renderTemplate(file=3D"static/intro.html") File "/usr/lib/python2.4/site-packages/cherrytemplate/cherrytemplate.py", line 407, in renderTemplate result =3D ''.join(list(result)) File "<string>", line 170, in _renderTemplate AttributeError: 'Admin' object has no attribute 'pageviews' =3D=3D=3DSecond Error=3D=3D=3D Traceback (most recent call last): File "/usr/lib/python2.4/site-packages/cherrypy/_cphttptools.py", line 398, in handleError _cputil.getSpecialAttribute('_cpOnError')() File "/usr/lib/python2.4/site-packages/cherrypy/_cputil.py", line 340, in _cpOnError cherrypy.HTTPError(500).set_response() File "/usr/lib/python2.4/site-packages/cherrypy/_cperror.py", line 163, in set_response handler(self.status, self.message) File "/usr/lib/python2.4/site-packages/cherrypy/_cputil.py", line 232, in _cpOnHTTPError cherrypy.log(logmsg, "HTTP") File "/usr/lib/python2.4/site-packages/cherrypy/__init__.py", line 88, in= log logfunc(msg, context, severity) File "/usr/lib/python2.4/site-packages/cherrypy/_cputil.py", line 133, in _cpLogMessage print s IOError: [Errno 5] Input/output error |