On Jul 10, 8:37 am, Ste <[email protected]> wrote: > Hello Group, > > I see the following behaviour which I can not explain (don't know > sqlalchemy too well though): > > I have the following table setup (heavily simplified): > > class WikiPage(Base): > __tablename__ = 'wiki_page' > id = Column(Integer, primary_key=True) > name = Column(Unicode(40)) > content = Column(UnicodeText()) > > def method_that_changes_something(self,...): > .... > > class Problem(WikiPage): > __tablename__ = 'problem' > __mapper_args__ = {'polymorphic_identity': 'problem'} > > id = Column(Integer, ForeignKey('wiki_page.id'), primary_key=True) > > Sometimes (so far only when run from a nose test suite) when I query > like this: > > problem = self.Session.query(Problem).filter_by(id=problem_id).first() > > where problem_id is None. I receive the unexpected result: > - not problem is False > - when applying str to the result I get: <my_app.model.Problem object > at 0x1040db710> > - there should be no Problems with id Null (though currently not > InnoDB tables, all pending changes have been commited and I do not see > any rows with NULL Ids in the DB) > - when I try to access problem.id I get: AttributeError: 'NoneType' > object has no attribute 'id' > - the same when I try to access problem.name > - problem.method_that_changes_something can be called and does > something (on an object that has been inserted before this query but > this is already commited) > - adding sleep(1) before the query changes nothing (so it does not > seem to be a race condition) > > Environement: > - Sqlalchemy 0.5.8 or 0.6.2 (behaves the same) > - Pylons 1.0 > - MySQL Python 1.2.3 > > So my questsions are: > - Am I doing something wrong? > - How can I persuade nosetests to output sqlalchemy log messages?
you'd want to put "echo='debug'" on your create_engine() statement, or if using nose add "--log-debug=sqlalchemy.engine" to the command line. You should be doing a pdb here so that you can more closely inspect the object you're getting back and further experimenting with the query object. I would suspect the means of testing the result is where the meaning of "problem" is being changed - pdb will eliminate that. -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.
