Posts

Showing posts from September, 2014

We don't know how to use SQLAlchemy sessions

We use sqlalchemy in ckan and often we run into problems with DetachedInstanceErrors. For this reason, we normally jam all the data from a model object into a dictionary to avoid getting the DetachedInstanceError. This isn't sqlachemy's fault, it's more than likely that we are just incapable of using it properly. For a while, we kept on running into issues where paster db clean would hang and I spent a while trying to figure out what the hell was going on and what was wrong with the session. As it turned out, there was nothing wrong session really, it was just that we were handling it badly for command line functions. There were basically 2 problems. Not closing transactions that are implicity opened by sqlalchemy Closing and removing a session and then attempting to use the sqlalchemy objects from that session causing DetachedInstanceErrors To demonstrate this, we're going to use do some fiddling with ckan from the ipython command line shell. We'll st