Re: [SQLObject] FW: longId=True handling...
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Oleg B. <ph...@ph...> - 2010-01-25 17:49:24
|
On Fri, Jan 22, 2010 at 09:57:13PM +0300, Oleg Broytman wrote: > In essence, the problem is in class sqlmeta, method setClass: > > if cls.idName is None: > cls.idName = cls.style.idForTable(cls.table) > > The method poisons the class so in any class inherited from sqlmeta idName > will be already set and the test fails. > Adding idName to the list of unshared attributes resets idName to None > but that prevents proper inheritance of idName. > To explain all this with code - with current SQLObject the following > code > > class sqlmeta(sqlmeta): > idName = 'ddd' > > class Test1(SQLObject): > class sqlmeta(sqlmeta): > style = MixedCaseStyle(longID=True) > > print Test1.sqlmeta.idName > > class Test2(SQLObject): > class sqlmeta: > style = MixedCaseStyle(longID=True) > > print Test2.sqlmeta.idName > > prints 'ddd' and 'id'; the first idName is right and the second one is > wrong (it must be 'Test2ID'). > The same code running with idName added to the list of unshared attributes > prints 'Test1ID' and 'Test2ID'; the first one is wrong (it must be 'ddd') > and the second one is right. > Probably the correct way of fixing it is to add idName (and 'style' > because setClass tests and sets it too) to the list of unshared attributes > but make sqlmeta.__classinit__ to recognize inherited attributes and do not > reset them. I will think of it... Well, instead of trying to find what was inherited and what was set in parent's setClass() I just prevented setClass() from poisoning the base sqlmeta. The patch is just Index: sqlobject/main.py =================================================================== --- sqlobject/main.py (revision 4089) +++ sqlobject/main.py (working copy) @@ -853,7 +853,8 @@ del values[key] cls.sqlmeta = type('sqlmeta', (superclass,), values) - cls.sqlmeta.setClass(cls) + if not is_base: # Do not pollute the base sqlmeta class + cls.sqlmeta.setClass(cls) _SO_setupSqlmeta = classmethod(_SO_setupSqlmeta) With the patch the code above prints 'ddd' and 'Test2ID' which is exactly right. The test suite passed so if nobody reports any problem with the patch I will apply it to the trunk. Oleg. -- Oleg Broytman http://phd.pp.ru/ ph...@ph... Programmers don't die, they just GOSUB without RETURN. |