[Twisted-web] Twisted and SQLAlchemy Cache Problem

Jean-Paul Calderone exarkun at divmod.com
Wed Jun 13 09:15:59 EDT 2007


On Wed, 13 Jun 2007 14:40:11 +0200, Magnus Hult <magnus at spotify.com> wrote:
>Hi,
>
>When executing the following program, changes in the database (other
>than those made by this program) aren't visible until it is restarted,
>due to some form of SQLAlchemy caching:
>
>from twisted.web import server, resource
>import model # my database model
>
>class MyRoot(resource.Resource):
>  def render(self, request):
>    m = model.MyModel.get(request.args['id'][0])
>    return m.some_column

Here, you're arranging to render whatever the expression `m.some_column'
evaluates to.  However that is implemented and whatever value it results
in, that's what will be rendered on the page.

> [snip - db and service setup]
>
>So if I visit http://localhost:8080/?id=1, then alter the some_column
>value for the row who's id is 1 and reload, the change is not
>reflected.
>
>Problem is, I need the update to be visible. How would I go about
>implementing this?
>

It would seem that `m.some_column' evaluates to the same value each time
the page is rendered.  Could it be that SQLAlchemy is performing some
undesirable caching which is preventing the new value from showing up?  I
am not particularly familiar with SQLAlchemy, so I'm not sure why this
might be.  It does seem like you want to be looking into SQLAlchemy behavior
to figure this out, though.

Hope this helps,

Jean-Paul



More information about the Twisted-web mailing list