Hi,
as I understand the documentation, sub-sub-classing InheritableSQLObject should be fine. But it messes with introspection, as demonstrated by the short attached script.

When there is no C and you create and retrieve B, everything works. Introduce C, and running it with an empty database (rm /tmp/x) still works:

<class '__main__.A'>
<class '__main__.B'>
X
<class '__main__.C'>
X

But run it again, so that the first list() actually does retrieve something, and it will raise:

<class '__main__.A'>
<class '__main__.B'>
X
<class '__main__.C'>
Traceback (most recent call last):
  File "desperate.py", line 23, in <module>
    list(B.select())
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLObject-0.12dev_r3970-py2.6.egg/ sqlobject/sresults.py", line 179, in __iter__
    return iter(list(self.lazyIter()))
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLObject-0.12dev_r3970-py2.6.egg/ sqlobject/inheritance/iteration.py", line 43, in next
    childResults=childResults, connection=self.dbconn)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLObject-0.12dev_r3970-py2.6.egg/ sqlobject/inheritance/__init__.py", line 309, in get
    selectResults=childResults)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLObject-0.12dev_r3970-py2.6.egg/ sqlobject/inheritance/__init__.py", line 309, in get
    selectResults=childResults)
File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLObject-0.12dev_r3970-py2.6.egg/ sqlobject/inheritance/__init__.py", line 290, in get val = super(InheritableSQLObject, cls).get(id, connection, selectResults) File "/opt/local/Library/Frameworks/Python.framework/Versions/2.6/ lib/python2.6/site-packages/SQLObject-0.12dev_r3970-py2.6.egg/ sqlobject/main.py", line 893, in get
    val._init(id, connection, selectResults)
  File "/Users/towb/Desktop/desperate.py", line 10, in _init
    print getattr(self, 'name')
  File "<string>", line 1, in <lambda>
AttributeError: 'NoneType' object has no attribute 'name'

I couldn't find out what actually happens as the code is full of eval()...
import sqlobject
from sqlobject.inheritance import InheritableSQLObject

class A(InheritableSQLObject):
    def _init(self, *args, **kargs):
        InheritableSQLObject._init(self, *args, **kargs)
        print self.__class__
        if 'name' in dir(self):
            # This should never fail
            print getattr(self, 'name')

class B(A):
    name = sqlobject.StringCol()

class C(B):
    pass

sqlobject.sqlhub.processConnection = sqlobject.connectionForURI('sqlite:/tmp/x')

for klass in (A, B, C):
    klass.createTable(ifNotExists = True)

list(B.select())
C(name = 'X')
list(B.select())
------------------------------------------------------------------------------
Let Crystal Reports handle the reporting - Free Crystal Reports 2008 30-Day 
trial. Simplify your report design, integration and deployment - and focus on 
what you do best, core application coding. Discover what's new with 
Crystal Reports now.  http://p.sf.net/sfu/bobj-july
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to