On Monday, 3 April 2017 21:54:28 UTC+2, Mikko Ohtamaa wrote: > > Hi Christian, > > I'm working on a project where I use Pyramid together with Cornice to >> provide a REST-API. When I do a PUT-request, I would like to return the >> updated resource in the Response. But as the COMMIT only happens after >> returning the Response and request.dbession.commit() is not allowed in the >> default configuration (SQLAlchemy-scaffold - "Transaction must be committed >> using the transaction manager"), I'm wondering how I could return the >> resource with the latest DB-State after updating it with the PUT-payload. >> Using a GET right after a successful PUT is my current solutions, but >> that feels like an unclean workaround. >> >> Is there a way to do this without replacing the whole >> transaction-mechanism, which seems complex? >> > > If I read this correctly this is not complex at all. > > Run: > > request.dbsession.flush() > > And SQLAlchemy will sync all in-memory objects from the database. >
While I already had flush() in place wherever necessary, your answer made me take a closer look at my model. I realized that I'm creating my JSON-Response from persisted, therefore outdated objects, not the newly created ones - that's why I didn't see my updates. Thanks for pointing me in the right direction! -- You received this message because you are subscribed to the Google Groups "pylons-discuss" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/35750d94-cc7b-4438-9604-99c5ff5616ce%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
