[SQLObject] sqlmeta, fromDatabase and "No connection has been defined" errors...
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Ray V. D. <rva...@es...> - 2008-07-09 01:10:11
|
Hi all, new to SQLObject, but already really enjoying it. I'm trying to pull in an SQLObject class from an already existing database schema, but having no success. It would seem to be pretty straightforward: import sys, os from sqlobject import * class Owners(SQLObject): class sqlmeta: table = 'Owners' fromDatabase = True def main(): conn = connectionForURI("mysql://virtual:pass@localhost/virtual?debug=1&debugOutput=1") sqlhub.processConnection = conn o = Owners.get(7) print o if __name__ == '__main__': main() However, this results in the following traceback: Traceback (most recent call last): File "./test3.py", line 6, in ? class Owners(SQLObject): File "/usr/lib/python2.4/site-packages/sqlobject/declarative.py", line 121, in __new__ cls.__classinit__(cls, new_attrs) File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 784, in __classinit__ cls.sqlmeta.addColumnsFromDatabase() File "/usr/lib/python2.4/site-packages/sqlobject/main.py", line 441, in addColumnsFromDatabase conn = connection or soClass._connection File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py", line 973, in __get__ return self.getConnection() File "/usr/lib/python2.4/site-packages/sqlobject/dbconnection.py", line 985, in getConnection raise AttributeError( AttributeError: No connection has been defined for this thread or process If I go ahead and just define the class myself (it's a simple one with only two columns), everything works fine and I can retrieve data as one would expect. Is there something more I need to do to attach a connection to my class? The above appears to be in line with most of the examples I've come across. This is with SQLObject 0.9.2 and MySQLdb 1.2.1. Thanks! Ray |