Skip to content

Commit 8d493d0

Browse files
Merge branch 'main' into WD-22501
2 parents ab343a0 + 39e9710 commit 8d493d0

File tree

3 files changed

+27
-10
lines changed

3 files changed

+27
-10
lines changed

migrate.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
from flask_migrate import upgrade
2+
3+
from webapp.app import app
4+
from webapp.context import database_lock
5+
6+
7+
def migrate() -> None:
8+
# Use lock to prevent multiple concurrent migrations on startup
9+
# Automatically upgrade to head revision
10+
with app.app_context(), database_lock():
11+
upgrade()
12+
13+
14+
if __name__ == "__main__":
15+
migrate()

rockcraft.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ parts:
2020
- flask/app/.env
2121
- flask/app/app.py
2222
- flask/app/data
23+
- flask/app/migrate.py
2324
- flask/app/migrations
2425
- flask/app/webapp
2526
- flask/app/templates

webapp/site_repository.py

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
import subprocess
44
import time
5+
import traceback
56
from collections.abc import Callable
67
from pathlib import Path
78
from typing import TypedDict
@@ -265,19 +266,18 @@ def get_tree_from_db(self):
265266
tree = get_tree_struct(db.session, webpages)
266267
# If the tree is empty, load from the repository
267268
if not tree or (
268-
tree.get("children") and not tree.get("parent_id")
269+
not tree.get("children") and not tree.get("parent_id")
269270
):
270271
msg = (
271272
"Reloading incomplete tree root "
272-
f"{self.repository_uri}."
273+
f"{self.repository_uri}. {tree}"
273274
)
274275
self.logger.info(
275276
msg,
276277
)
277278
tree = self.get_new_tree()
278279
return tree
279-
# Raise an error if the project does not exist.
280-
raise SiteRepositoryError("Invalid project_id. Unable to load tree.")
280+
return None
281281

282282
def get_tree(self, no_cache: bool = False):
283283
"""Get the tree from the cache or load a new tree to cache and db."""
@@ -403,14 +403,15 @@ def get_tree_sync(self, no_cache: bool = False):
403403
self.invalidate_cache()
404404

405405
# Load the tree from database
406-
try:
407-
tree = self.get_tree_from_db()
406+
if tree := self.get_tree_from_db():
408407
self.logger.info(f"Tree refreshed for {self.repository_uri}")
409-
# Update the cache
410-
self.set_tree_in_cache(tree)
408+
try:
409+
# Update the cache
410+
self.set_tree_in_cache(tree)
411+
except Exception as e:
412+
self.logger.exception(traceback.format_exc())
413+
self.logger.error(f"Unable to save tree to cache: {e}")
411414
return tree
412-
except Exception as e:
413-
self.logger.error(f"Error loading tree: {e}")
414415

415416
# Or just return an empty tree
416417
return {

0 commit comments

Comments
 (0)