sqlalchemy - SQL Alchemy + Testing webserver with InnoDB fails -
i trying move db tables on innodb myisam. having timing issues requests , cron jobs running on server leading errors. quite sure transaction support me problem. therefore transitioning innodb.
i have suite of tests make calls our webservices rest api , receive xml responses. test suite thorough, , it's written in python , uses sqlalchemy query information database. when change tables in system myisam innodb however, tests start failing. however, tests aren't failing because system isn't working, failing because orm not correctly querying rows database testing on. when step through code see correct results, orm not returning correct results @ all.
basic flow is:
class unittest(unittest.testcase): def setup(self): # create test object in db gets affected web server testobject = obj(foo='one') self.testid = testobject.id session.add(testobject) session.commit() def teardown(self): # clean after test testobject = session.query(obj).get(self.testid) session.delete(testobject) session.commit() def test_web_server(self): # ensure initial state of object. objects = session.query(obj).get(self.testid) assert objects.foo == 'one' # make simple http call on url modify db response = server.request.increment_foo(self.testid) # 1 fails, object still has foo of 'one' # when stop here in debugger though, , @ database, # row in question has correct value in database. # ???? objects = session.query(obj).get(self.testid) assert objects.foo == 'two'
using myisam tables store object , test pass. however, when change innodb tables, test not pass. more interesting when step through code in debugger, can see datbase has expect, it's not problem in web server code. have tried every combination of expire_all, autoflush, autocommit, etc. etc, , still can't test pass.
i can provide more info if necessary.
thanks, conrad
the problem put line self.testid = testobject.id
before new object added session, flushed, , sqlalchemy assigned id it. self.testid
none
. move line below session.commit()
.
Comments
Post a Comment