if you implement some kind of __getattr__() method which raises an exception, Python will usually squash it if you say hasattr(x, 'foo'). it interprets every exception, not just AttributeError, as "no such attribute". I think py3k might change this behavior. But if you're seeing exceptions magically disappear, this kind of thing is a candidate (meaning, SQLA deals alot with custom attribute access). SQLA should log that mapper compilation failed and on the next compile_mappers(), will tell you so. try calling it twice.
On Apr 3, 1:21 pm, "phrrn...@googlemail.com" <phrrn...@googlemail.com> wrote: > OK. This appears to be the source of the problem. You may recall a > couple of weeks ago that I was looking for information on how to > surface comments from the database metadata into the sqlalchemy model > and into docstrings in mapped classes? I took your suggestion and > modified it slightly. When I comment out this code, everything seems > to work just fine (although I have been hacking on our code so much > yesterday and today that I may have to revert back to the last copy in > svn to be sure) > > Do you have any idea who/what is gobbing up the exception? I am about > to unleash my SA code generator on our internal developer community > but would really like to understand how to debug this kind of issue > better so that I don't get killed debugging the generated code! > > pjjH > > # class AttachNotesAsDocstring(interfaces.InstrumentationManager): > # def instrument_attribute(self, class_, key, attr): > # if isinstance(attr.property, properties.ColumnProperty): > # if hasattr(attr.property.columns[0], 'info'): > # attr.__doc__ = attr.property.columns[0].info.get > ('notes') > > # attributes.instrumentation_finders.insert(0, lambda cls: > AttachNotesAsDocstring) > > On Apr 3, 12:57 pm, "phrrn...@googlemail.com" > > <phrrn...@googlemail.com> wrote: > > I did RTFM athttp://www.python.org/doc/2.5.2/ref/import.htmlandnow > > have the symbols explicitly enumerated in the __all__ attribute in the > > module. However, I am still getting this error when I attempt to do > > an ORM query on any of these: > > q = s.query(_ForeignKey).filter(_ForeignKey.FKTABLE_NAME == 'banana') > > for i in q: > > print i > > > q = s.query(_Index).filter(_Index.INDEX_NAME == 'banana') > > for i in q: > > print i > > > q = s.query(_PrimaryKey).filter(_PrimaryKey.TABLE_NAME == 'banana') > > for i in q: > > print i > > > I get the same error each time: > > AttributeError: 'ColumnProperty' object has no attribute 'strategy' > > > I have tried prepending 'Banana' onto the symbols starting with an > > underscore but am still getting the same error: > > > q = s.query(Banana_Index).filter(Banana_Index.INDEX_NAME == 'banana') > > for i in q: > > print i > > > I am not aware of anything that is catching any exceptions. > > > pjjH > > > __all__ = [ > > "Attribute", > > "Catalog", > > "DatabaseTable", > > "Dataserver", > > "Sample", > > "_ExtendedProperty", > > "_ForeignKey", > > "_ForeignKeyElement", > > "_Index", > > "_IndexElement", > > "_PrimaryKey", > > "_PrimaryKeyElement", > > ] > > > On Apr 3, 11:58 am, "phrrn...@googlemail.com" > > > <phrrn...@googlemail.com> wrote: > > > So I guess that symbols starting with underscore ('_') are treated > > > differently in Python when it comes to be exporting/importing? Sorry > > > to be such a newb but this is the only conclusion I can (rationally!) > > > come to. > > > > Traceback (most recent call last): > > > File "chimera_driver.py", line 42, in <module> > > > q = s.query(_PrimaryKey).filter(_PrimaryKey.TABLE_NAME == > > > 'banana') > > > NameError: name '_PrimaryKey' is not defined > > > > pjjH > > > > On Apr 3, 11:34 am, "phrrn...@googlemail.com" > > > > <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 -~----------~----~----~----~------~----~------~--~---