Skip to content
This repository was archived by the owner on Jun 30, 2024. It is now read-only.

Commit 0ec7dc6

Browse files
committed
Avoid crashing if no request
1 parent 40ea94d commit 0ec7dc6

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

scripts/tickets2db.py

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,12 @@
1515

1616
SLEEP_MINUTES = 5
1717

18-
errors_path = os.path.join(request.folder, 'errors')
18+
errors_path = os.path.join(request.folder, "errors")
1919

20-
if os.environ['WEB2PY_CONFIG'] == "production":
21-
db_string = os.environ['DBURL']
22-
elif os.environ['WEB2PY_CONFIG'] == "development":
23-
db_string = os.environ['DEV_DBURL']
20+
if os.environ["WEB2PY_CONFIG"] == "production":
21+
db_string = os.environ["DBURL"]
22+
elif os.environ["WEB2PY_CONFIG"] == "development":
23+
db_string = os.environ["DEV_DBURL"]
2424
else:
2525
# no need to run during testing
2626
sys.exit(0)
@@ -43,32 +43,35 @@
4343

4444
modified_time = os.stat(filename)[stat.ST_MTIME]
4545
modified_time = datetime.datetime.fromtimestamp(modified_time)
46-
with open(filename, 'rb') as f:
46+
with open(filename, "rb") as f:
4747
ticket_data = pickle.load(f)
4848
ticket_id = file
49-
traceback_str = ticket_data['traceback']
50-
emess = ticket_data['output']
51-
soup = BeautifulSoup(ticket_data['snapshot']['request'].text)
52-
path = ""
53-
query_string = ""
54-
for row in soup.find_all('tr'):
55-
if row.get_text().startswith('raw_uri'):
56-
path = row.get_text()
57-
if row.get_text().startswith('query_string'):
58-
query_string = row.get_text()
59-
if path:
60-
path = path.split(":")[-1]
61-
if query_string:
62-
query_string = query_string.split(":")[-1]
63-
49+
traceback_str = ticket_data["traceback"]
50+
emess = ticket_data["output"]
51+
try:
52+
soup = BeautifulSoup(ticket_data["snapshot"]["request"].text)
53+
path = ""
54+
query_string = ""
55+
for row in soup.find_all("tr"):
56+
if row.get_text().startswith("raw_uri"):
57+
path = row.get_text()
58+
if row.get_text().startswith("query_string"):
59+
query_string = row.get_text()
60+
if path:
61+
path = path.split(":")[-1]
62+
if query_string:
63+
query_string = query_string.split(":")[-1]
64+
except:
65+
path = ""
66+
query_string = ""
6467
newtb = traceback.insert().values(
6568
traceback=traceback_str,
6669
timestamp=datetime.datetime.utcnow(),
67-
err_message=ticket_data['output'],
68-
hostname='web2py',
70+
err_message=ticket_data["output"],
71+
hostname="web2py",
6972
path=path,
7073
query_string=query_string,
71-
hash=hashlib.md5(traceback_str.encode("utf8")).hexdigest()
74+
hash=hashlib.md5(traceback_str.encode("utf8")).hexdigest(),
7275
)
7376
sess.execute(newtb)
7477
sess.commit()

0 commit comments

Comments
 (0)