-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
45 lines (35 loc) · 1.01 KB
/
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
from flask import Flask
from flask.ext.sqlalchemy import SQLAlchemy
from models import db, TestTicket, TicketStatus, Ticket
app = Flask(__name__)
db.init_app(app)
with app.app_context():
db.create_all()
db.session.commit()
@app.route('/')
def index():
# This will fail on the first run
try:
result = db.session.query(Ticket) \
.filter(Ticket.status == TicketStatus.open) \
.all()
except:
print('query failed')
else:
print('query successful')
# If I query the subclass, everything will work fine
db.session.query(TestTicket) \
.filter(Ticket.status == TicketStatus.open) \
.all()
# Try running the query again
try:
result = db.session.query(Ticket) \
.filter(Ticket.status == TicketStatus.open) \
.all()
except:
print('query failed on second try')
else:
print('query successful on second try')
return '', 200
if __name__ == '__main__':
app.run(debug=True)