From 97b4cda06dd89b7901a4e91e070cf0e2e63a37e4 Mon Sep 17 00:00:00 2001 From: Marek Spano <2093904+luxusko@users.noreply.github.com> Date: Tue, 5 Sep 2023 08:35:45 +0200 Subject: [PATCH] Add username to failed syncs [#861n6f0z0](https://app.clickup.com/t/861n6f0z0) --- server/mergin/sync/models.py | 10 +++++++--- server/mergin/sync/public_api_controller.py | 9 +++++++-- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/server/mergin/sync/models.py b/server/mergin/sync/models.py index c05bd7e9..527f99e5 100644 --- a/server/mergin/sync/models.py +++ b/server/mergin/sync/models.py @@ -165,9 +165,11 @@ def file_history(self, file, since, to, diffable=False): return history - def sync_failed(self, client, error_type, error_details): + def sync_failed(self, client, error_type, error_details, username): """Commit failed attempt to sync failure history table""" - new_failure = SyncFailuresHistory(self, client, error_type, error_details) + new_failure = SyncFailuresHistory( + self, client, error_type, error_details, username + ) db.session.add(new_failure) db.session.commit() @@ -583,13 +585,15 @@ class SyncFailuresHistory(db.Model): ) # e.g. push_start, push_finish, push_lost error_details = db.Column(db.String, index=True) timestamp = db.Column(db.DateTime(), default=datetime.utcnow, index=True) + username = db.Column(db.String, nullable=True) - def __init__(self, project, ua, err_type, err_details): + def __init__(self, project, ua, err_type, err_details, username): self.user_agent = ua self.error_type = err_type self.error_details = err_details self.project_id = project.id self.last_version = project.latest_version + self.username = username class GeodiffActionHistory(db.Model): diff --git a/server/mergin/sync/public_api_controller.py b/server/mergin/sync/public_api_controller.py index ffece318..231307e9 100644 --- a/server/mergin/sync/public_api_controller.py +++ b/server/mergin/sync/public_api_controller.py @@ -675,7 +675,9 @@ def wrapper(*args, **kwargs): if not e.description: # custom error cases (e.g. StorageLimitHit) e.description = e.response.json["detail"] if project: - project.sync_failed(user_agent, error_type, str(e.description)) + project.sync_failed( + user_agent, error_type, str(e.description), current_user.username + ) else: logging.warning("Missing project info in sync failure") @@ -810,7 +812,10 @@ def project_push(namespace, project_name): db.session.commit() # previous push attempt is definitely lost project.sync_failed( - "", "push_lost", "Push artefact removed by subsequent push" + "", + "push_lost", + "Push artefact removed by subsequent push", + current_user.username, ) # Try again after cleanup