at the point you request model.id , the new model has not yet reached the database; The pyramid waits until the request handler returns before it makes a pending transaction. To get the identifier earlier, you must clear the session. Add:
model = Model('some_title', 'some text') session.add(model) session.flush() return HTTPFound(location='/ads/%s/%s' % (model.id, model.title))
source share