I copied the list of import statements from the module file
(deshaw.dbo.chimera) to the driver file. The driver file also has a
line:
from deshaw.dbo.chimera import *

Note that this is happening with a particular class, DatabaseTable,
*not* with other classes I have declared and mapped such as
Dataserver. Interestingly, the DatabaseClass works when I comment out
a bunch of relations:


mapper(DatabaseTable, tables, properties = {
#      'attributes'             : relation(Attribute,  lazy=False,
order_by = asc(Attribute.ORDINAL_POSITION)),
#      'primary_key'            : relation(_PrimaryKey, uselist=False,
lazy=False), # At most one PK is allowed.
#      'indexes'                : relation(_Index,lazy=False),
#      'foreign_keys'           : relation(_ForeignKey,
lazy=False)
})

I experimented with adding the properties later on after everything
else had been defined but still get the same error

class_mapper(DatabaseTable).add_properties({
#      'attributes'             : relation(Attribute,  lazy=False,
order_by = asc(Attribute.ORDINAL_POSITION)),
#      'primary_key'            : relation(_PrimaryKey, uselist=False,
lazy=False), # At most one PK is allowed.
#      'indexes'                : relation(_Index,lazy=False),
#      'foreign_keys'           : relation(_ForeignKey,
lazy=False)
})

How do I find out what is special about 'DatabaseTable' or, more
precisely, the properties I am trying to define on it. I tried putting
compile_mappers() in both the module and the driver but it has no
impact. I assume that one of 'attributes', 'primary_key', 'indexes' or
'foreign_keys' is already in use .. OK. Let me try that:

class_mapper(DatabaseTable).add_properties({
#      'apple'             : relation(Attribute,  lazy=False, order_by
= asc(Attribute.ORDINAL_POSITION)),
#      'banana'            : relation(_PrimaryKey, uselist=False,
lazy=False), # At most one PK is allowed.
      'pear'                : relation(_Index,lazy=False),
#      'kiwi'           : relation(_ForeignKey, lazy=False)
})

No, didn't do anything. Let's try with lazy=True. OK that works. Let's
try lazy=True with the original names. OK. That works also. So the
problem appears to be with setting lazy=True for these properties.

What is the debugging incantation to debug the orm mapping? Or do you
have any advice on how to proceed from here?

thanks,

pjjH



On Apr 2, 9:20 pm, Michael Bayer <zzz...@gmail.com> wrote:
> make sure everything that's needed is imported, and that you arent
> suppressing any exceptions which occur when the mappers first compile
> themselves.   try calling compile_mappers() to force the issue.
>
> On Apr 2, 8:19 pm, "phrrn...@googlemail.com" <phrrn...@googlemail.com>
> wrote:
>
> > This code works when executed within a if __name__ == '__main__'
> > block in the .py that contains the model:
>
> > s = MySession(bind=e)
> > q = s.query(DatabaseTable).filter(DatabaseTable.TABLE_CAT=='credit')
> > for i in q:
> >     print i
>
> > However, if I take it out and put it in a separate file, I get an
> > error like this. I hope that this is something simple that I am doing
> > wrong?
> > pjjH
>
> > Traceback (most recent call last):
> >   File "H:\work\base_python\python\chimera_driver.py", line 14, in
> > <module>
> >     for i in q:
> >   File "C:\PROGRA~1\Python25\lib\site-packages\sqlalchemy-0.5.2-
> > py2.5.egg\sqlalchemy\orm\query.py", line 1276, in __iter__
> >     context = self._compile_context()
> >   File "C:\PROGRA~1\Python25\lib\site-packages\sqlalchemy-0.5.2-
> > py2.5.egg\sqlalchemy\orm\query.py", line 1718, in _compile_context
> >     entity.setup_context(self, context)
> >   File "C:\PROGRA~1\Python25\lib\site-packages\sqlalchemy-0.5.2-
> > py2.5.egg\sqlalchemy\orm\query.py", line 1972, in setup_context
> >     column_collection=context.primary_columns
> >   File "C:\PROGRA~1\Python25\lib\site-packages\sqlalchemy-0.5.2-
> > py2.5.egg\sqlalchemy\orm\interfaces.py", line 580, in setup
> >     self.__get_context_strategy(context, path +
> > (self.key,)).setup_query(context, entity, path, adapter, **kwargs)
> >   File "C:\PROGRA~1\Python25\lib\site-packages\sqlalchemy-0.5.2-
> > py2.5.egg\sqlalchemy\orm\interfaces.py", line 566, in __get_context_
> > strategy
> >     return self.strategy
> > AttributeError: 'RelationProperty' object has no attribute 'strategy'
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to