I don't see any output from it at all. I am calling it after importing everything but before making any queries. The mapper registry looks unsurprising (albeit based on a guess of what it does)
pjjH from sqlalchemy.orm import compile_mappers s = MySession(bind=e) print compile_mappers() q = s.query(Dataserver) (Pdb) p _mapper_registry <WeakKeyDictionary at 139496364> (Pdb) p _mapper_registry.keys() [<Mapper at 0x8669e6c; _PrimaryKeyElement>, <Mapper at 0x866eb0c; _ForeignKeyElement>, <Mapper at 0x868272c; _ForeignKey>, <Mapper at 0x861fe8c; Attribute>, <Mapper at 0x868ea0c; Sample>, <Mapper at 0x8676bac; _Index>, <Mapper at 0x865ca6c; _IndexElement>, <Mapper at 0x861f40c; _ExtendedProperty>, <Mapper at 0x8687c0c; Dataserver>, <Mapper at 0x868786c; Catalog>, <Mapper at 0x868730c; DatabaseTable>, <Mapper at 0x867da0c; _PrimaryKey>] (Pdb) n > /usr/local/python-2.5.1/lib/python2.5/site-packages/SQLAlchemy-0.5.2-py2.5.egg/sqlalchemy/orm/__init__.py(842)compile_mappers() -> m.compile() (Pdb) p m <Mapper at 0x8669e6c; _PrimaryKeyElement> (Pdb) p repr(m) '<Mapper at 0x8669e6c; _PrimaryKeyElement>' (Pdb) p str(m) 'Mapper|_PrimaryKeyElement|widened_sp_primarykeys' On Apr 3, 1:37 pm, "Michael Bayer" <mike...@zzzcomputing.com> wrote: > what does compile_mappers() say? can you call this mapper, and at the > same time all mappers within the entire application have been called ? > > phrrn...@googlemail.com wrote: > > > 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 -~----------~----~----~----~------~----~------~--~---