Commit 060cad93 authored by Martin Mareš's avatar Martin Mareš
Browse files

App: Reset DB transactions properly

Otherwise we can serve stale data.
parent 2387761f
import json
from flask import Flask, render_template, request, g
from flask import Flask, render_template, request, g, request_tearing_down
import psycopg2
import psycopg2.extras
import time
......@@ -42,6 +42,17 @@ def db_query(query, args=()):
db_connect()
db.execute(query, args)
def db_reset_signal(sender, **extra):
# At the end of every request, we have to close the implicitly opened
# transaction. Otherwise we end up with serving stale data.
if db_connection is not None:
try:
db_connection.rollback()
except:
pass
request_tearing_down.connect(db_reset_signal, app)
### Schedule ###
def get_date():
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment