From 14b3cfca556ae117e0f28017a0b2516a19c1ec7d Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 1 Feb 2021 18:40:11 +0200 Subject: [PATCH] Handle stoken being the empty string. For whatever reason some users were getting this which was causing this code to fail. --- etebase_fastapi/routers/collection.py | 2 +- etebase_fastapi/stoken_handler.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/etebase_fastapi/routers/collection.py b/etebase_fastapi/routers/collection.py index 167179d..c8146f2 100644 --- a/etebase_fastapi/routers/collection.py +++ b/etebase_fastapi/routers/collection.py @@ -473,7 +473,7 @@ def item_bulk_common( with transaction.atomic(): # We need this for locking the collection object collection_object = queryset.select_for_update().get(uid=uid) - if stoken is not None and stoken != collection_object.stoken: + if stoken and stoken != collection_object.stoken: raise HttpError("stale_stoken", "Stoken is too old", status_code=status.HTTP_409_CONFLICT) data.validate_db() diff --git a/etebase_fastapi/stoken_handler.py b/etebase_fastapi/stoken_handler.py index 76d348a..b6f2999 100644 --- a/etebase_fastapi/stoken_handler.py +++ b/etebase_fastapi/stoken_handler.py @@ -12,7 +12,7 @@ StokenAnnotation = t.Any def get_stoken_obj(stoken: t.Optional[str]) -> t.Optional[Stoken]: - if stoken is not None: + if stoken: try: return Stoken.objects.get(uid=stoken) except Stoken.DoesNotExist: