Thread: [SQLObject] Column name can not be the same as table name?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Brian C. <br...@te...> - 2007-07-04 14:44:18
|
Hello All, Just started using SQLObject yesterday, so if I made a rookie mistake please tell me. It appears SQLObject doesn't allow me to have the same column name as my table name. Here is the MySQL table definition: CREATE TABLE `sysname` ( `sysname_id` int(11) NOT NULL auto_increment, `sysname` varchar(64) NOT NULL, PRIMARY KEY (`sysname_id`) ) ENGINE=InnoDB DEFAULT CHARSET=utf8 And the corresponding SQLObject code: class Sysname(SQLObject): class sqlmeta: fromDatabase = True idName = "sysname_id" def getSysnameID(cls): sysname = platform.system() for s in cls.selectBy(sysname=sysname): return s.id return cls(sysname=sysname).id getSysnameID = classmethod(getSysnameID) print Sysname.getSysnameID() I get the following traceback from SQLObject: Traceback (most recent call last): File "knightly/machine.py", line 22, in ? print Sysname.getSysnameID() File "knightly/machine.py", line 16, in getSysnameID for s in cls.selectBy(sysname=sysname): File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/sresults.py", line 185, in __iter__ return iter(list(self.lazyIter())) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/sresults.py", line 193, in lazyIter return conn.iterSelect(self) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/dbconnection.py", line 400, in iterSelect select, keepConnection=False) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/dbconnection.py", line 636, in __init__ self.query = self.dbconn.queryForSelect(select) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/dbconnection.py", line 414, in queryForSelect return self.sqlrepr(select.queryForSelect()) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/sresults.py", line 45, in queryForSelect columns = [self.sourceClass.q.id] + [getattr(self.sourceClass.q, x.name) for x in self.sourceClass.sqlmeta.columnList] File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/sqlbuilder.py", line 386, in __getattr__ return self._getattrFromForeignKey(column, attr) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/sqlbuilder.py", line 403, in _getattrFromForeignKey ret = getattr(self, column.name)==getattr(self.soClass, '_SO_class_'+column.foreignKey).q.id TypeError: cannot concatenate 'str' and 'NoneType' objects If I change the column's name `sysname` to `name` and change the code accordingly everything works fine. Is this a feature or a bug? Thanks, Brian |
From: Oleg B. <ph...@ph...> - 2007-07-04 15:51:10
|
On Wed, Jul 04, 2007 at 08:44:15AM -0600, Brian Cole wrote: > CREATE TABLE `sysname` ( > `sysname_id` int(11) NOT NULL auto_increment, > `sysname` varchar(64) NOT NULL, > PRIMARY KEY (`sysname_id`) > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 > > '_SO_class_'+column.foreignKey).q.id > TypeError: cannot concatenate 'str' and 'NoneType' objects I suspect SQLObject has problems getting column decriptions from the database (due to fromDatabase). To start debugging print Sysname.sqlmeta.columns - do they look right? Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Brian C. <br...@te...> - 2007-07-05 15:12:58
|
The columns look fine: {'sysname': <SOStringCol sysname default=''>, 'sysnameID': <SOIntCol sysnameID default=None>} Where's the next place to look? -Brian On 7/4/07, Oleg Broytmann <ph...@ph...> wrote: > On Wed, Jul 04, 2007 at 08:44:15AM -0600, Brian Cole wrote: > > CREATE TABLE `sysname` ( > > `sysname_id` int(11) NOT NULL auto_increment, > > `sysname` varchar(64) NOT NULL, > > PRIMARY KEY (`sysname_id`) > > ) ENGINE=InnoDB DEFAULT CHARSET=utf8 > > > > '_SO_class_'+column.foreignKey).q.id > > TypeError: cannot concatenate 'str' and 'NoneType' objects > > I suspect SQLObject has problems getting column decriptions from the > database (due to fromDatabase). To start debugging print Sysname.sqlmeta.columns > - do they look right? > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
From: Oleg B. <ph...@ph...> - 2007-07-05 15:22:47
|
On Thu, Jul 05, 2007 at 09:12:43AM -0600, Brian Cole wrote: > {'sysname': <SOStringCol sysname default=''>, 'sysnameID': <SOIntCol > sysnameID default=None>} > > > > '_SO_class_'+column.foreignKey).q.id > > > TypeError: cannot concatenate 'str' and 'NoneType' objects Seems like a bug in SQLBuilder in the trunk - it recognized sysnameID as a ForeignKey. I will contact the author of that part of the code. Meanwhile, can you downgrade to a stable branch and test? 0.9.0 is the current stable release. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Brian C. <br...@te...> - 2007-07-05 16:19:57
|
Changed to this tag: SQLObject/tags/0.9.0b2/ Appears it can't even create the class anymore under this tag: Traceback (most recent call last): File "sqlobject_crash.py", line 17, in ? class Sysname(SQLObject): File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/declarative.py", line 117, in __new__ cls.__classinit__(cls, new_attrs) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/main.py", line 792, in __classinit__ cls.sqlmeta.addColumnsFromDatabase() File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/main.py", line 450, in addColumnsFromDatabase for columnDef in conn.columnsFromSchema(sqlmeta.table, soClass): File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/mysql/mysqlconnection.py", line 209, in columnsFromSchema colData = self.queryAll("SHOW COLUMNS FROM %s" File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/dbconnection.py", line 355, in queryAll return self._runWithConnection(self._queryAll, s) File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/dbconnection.py", line 253, in _runWithConnection conn = self.getConnection() File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/dbconnection.py", line 264, in getConnection conn = self.makeConnection() File "/Users/coleb/svn_knightly/trunk/backend/knightly/lib/sqlobject/mysql/mysqlconnection.py", line 82, in makeConnection conn.set_character_set(self.dbEncoding) File "/sw/lib/python2.4/site-packages/MySQLdb/connections.py", line 277, in set_character_set super(Connection, self).set_character_set(charset) TypeError: argument 1 must be string, not None -Brian On 7/5/07, Oleg Broytmann <ph...@ph...> wrote: > On Thu, Jul 05, 2007 at 09:12:43AM -0600, Brian Cole wrote: > > {'sysname': <SOStringCol sysname default=''>, 'sysnameID': <SOIntCol > > sysnameID default=None>} > > > > > > '_SO_class_'+column.foreignKey).q.id > > > > TypeError: cannot concatenate 'str' and 'NoneType' objects > > Seems like a bug in SQLBuilder in the trunk - it recognized sysnameID as > a ForeignKey. I will contact the author of that part of the code. > Meanwhile, can you downgrade to a stable branch and test? 0.9.0 is the > current stable release. > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
From: Oleg B. <ph...@ph...> - 2007-07-05 16:31:55
|
On Thu, Jul 05, 2007 at 10:19:45AM -0600, Brian Cole wrote: > Changed to this tag: SQLObject/tags/0.9.0b2/ This is pre-0.9.0 beta, there is 0.9.0 release. > conn.set_character_set(self.dbEncoding) > File "/sw/lib/python2.4/site-packages/MySQLdb/connections.py", line > 277, in set_character_set > super(Connection, self).set_character_set(charset) > TypeError: argument 1 must be string, not None This has been fixed in 0.9.0. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Brian C. <br...@te...> - 2007-07-05 16:38:13
|
Where is that in subversion? Or are tar balls only available? -Brian On 7/5/07, Oleg Broytmann <ph...@ph...> wrote: > On Thu, Jul 05, 2007 at 10:19:45AM -0600, Brian Cole wrote: > > Changed to this tag: SQLObject/tags/0.9.0b2/ > > This is pre-0.9.0 beta, there is 0.9.0 release. > > > conn.set_character_set(self.dbEncoding) > > File "/sw/lib/python2.4/site-packages/MySQLdb/connections.py", line > > 277, in set_character_set > > super(Connection, self).set_character_set(charset) > > TypeError: argument 1 must be string, not None > > This has been fixed in 0.9.0. > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
From: Brian C. <br...@te...> - 2007-07-05 16:45:49
|
Tested using the 0.9.0 tar ball from the CheeseShop and it works fine. -Brian On 7/5/07, Brian Cole <br...@te...> wrote: > Where is that in subversion? Or are tar balls only available? > > -Brian > > On 7/5/07, Oleg Broytmann <ph...@ph...> wrote: > > On Thu, Jul 05, 2007 at 10:19:45AM -0600, Brian Cole wrote: > > > Changed to this tag: SQLObject/tags/0.9.0b2/ > > > > This is pre-0.9.0 beta, there is 0.9.0 release. > > > > > conn.set_character_set(self.dbEncoding) > > > File "/sw/lib/python2.4/site-packages/MySQLdb/connections.py", line > > > 277, in set_character_set > > > super(Connection, self).set_character_set(charset) > > > TypeError: argument 1 must be string, not None > > > > This has been fixed in 0.9.0. > > > > Oleg. > > -- > > Oleg Broytmann http://phd.pp.ru/ ph...@ph... > > Programmers don't die, they just GOSUB without RETURN. > > > > ------------------------------------------------------------------------- > > This SF.net email is sponsored by DB2 Express > > Download DB2 Express C - the FREE version of DB2 express and take > > control of your XML. No limits. Just data. Click to get it now. > > http://sourceforge.net/powerbar/db2/ > > _______________________________________________ > > sqlobject-discuss mailing list > > sql...@li... > > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > > > |
From: Oleg B. <ph...@ph...> - 2007-07-05 16:44:28
|
On Thu, Jul 05, 2007 at 10:38:08AM -0600, Brian Cole wrote: > Where is that in subversion? Or are tar balls only available? Releases are as usual at Cheeseshop (are you new to Python at all?) http://www.python.org/pypi/SQLObject http://cheeseshop.python.org/pypi/SQLObject (I don't know which one is the canonical address :) About the Subversion repository. Branches are for continued development between releases. Tags mark particular releases including beta releases: http://svn.sqlobject.org/SQLObject/tags/0.9.0/ Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Brian C. <br...@te...> - 2007-07-05 17:01:03
|
Not new to python by any means. But this is the first time in 3 years that I'm creating something entirely from python. Usually I work on wrapping C++ libraries into Python (and Java). So I haven't had the need to use any third-party libraries in a while. A lot has changed in three years. =-) Anyway, I'm developing an internal nightly build/unittest/benchmark system across many different architectures. Python is perfect for the backend with a database to hold all the information. Someone else is going to build a web frontend to the database. Portability and ease of installation onto new machines is a chief concern. This is why I linked my subversion repository directly to yours. This alleviates the need to install SQLObject and formencode onto every machine as it's included directly into my package. Is there something inheritantly evil about this? Should I stick to the 0.9.0 tag? Or can/should I use trunk? This problem wasn't a show stopper as the work-around was fairly straight forward. Plus I'm still developing so I can keep a close eye on stability. Once I release I may revert to the latest SQLObject release. Thanks for you help, Brian On 7/5/07, Oleg Broytmann <ph...@ph...> wrote: > On Thu, Jul 05, 2007 at 10:38:08AM -0600, Brian Cole wrote: > > Where is that in subversion? Or are tar balls only available? > > Releases are as usual at Cheeseshop (are you new to Python at all?) > > http://www.python.org/pypi/SQLObject > http://cheeseshop.python.org/pypi/SQLObject > (I don't know which one is the canonical address :) > > About the Subversion repository. Branches are for continued development > between releases. Tags mark particular releases including beta releases: > > http://svn.sqlobject.org/SQLObject/tags/0.9.0/ > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > > ------------------------------------------------------------------------- > This SF.net email is sponsored by DB2 Express > Download DB2 Express C - the FREE version of DB2 express and take > control of your XML. No limits. Just data. Click to get it now. > http://sourceforge.net/powerbar/db2/ > _______________________________________________ > sqlobject-discuss mailing list > sql...@li... > https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss > |
From: Oleg B. <ph...@ph...> - 2007-07-05 17:12:45
|
On Thu, Jul 05, 2007 at 11:00:58AM -0600, Brian Cole wrote: > system across many different architectures. Python is perfect for the > backend with a database to hold all the information. Someone else is > going to build a web frontend to the database. Definitely. Our company uses SQLObject for portable DB access (SQLite and Postgres) and wxPython for portable GUI. > Portability and ease of installation onto new machines is a chief > concern. This is why I linked my subversion repository directly to > yours. This alleviates the need to install SQLObject and formencode > onto every machine as it's included directly into my package. Is there > something inheritantly evil about this? Nothing evil, but you can be beaten by bugs - the trunk is by definition unstable. > Should I stick to the 0.9.0 tag? If you prefer stability. > Or can/should I use trunk? You can, of course. I usually try to do even trunk as stable as possible, but the current situation is a bit harder. Luke Opperman did a lot of work in the trunk (he merged .select(), sqlbuilder.Select() and dbconnection.queryForSelect()) and there are still some rough corners. Thank you for spotting the bug. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Oleg B. <ph...@ph...> - 2007-07-05 17:33:11
|
Just a reminder - from time to time I publish tarballs from the Subversion at http://phd.pp.ru/Software/Python/misc/SQLObject/ Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Oleg B. <ph...@ph...> - 2007-07-05 17:28:02
|
Luke answered and sent a fix. I committed the bugfix a minute ago (rev 2730.) You can try the trunk again. Oleg. -- Oleg Broytmann http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |
From: Brian C. <br...@te...> - 2007-07-05 18:16:10
|
Thanks, I'll continue to use trunk for now (I get that warm fuzzy feeling inside when I contribute to projects I use). -Brian On 7/5/07, Oleg Broytmann <ph...@ph...> wrote: > Luke answered and sent a fix. I committed the bugfix a minute ago (rev 2730.) > You can try the trunk again. > > Oleg. > -- > Oleg Broytmann http://phd.pp.ru/ ph...@ph... > Programmers don't die, they just GOSUB without RETURN. > |