Skip to content
Snippets Groups Projects
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
No related branches found
No related tags found
No related merge requests found
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():
......
......@@ -2,3 +2,4 @@ zoomus
psycopg2
python-dateutil
Flask
blinker
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment