From a7fdb4a1082b3d84a6ee7e7eae1086412124b183 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Tue, 29 Dec 2020 20:56:36 +0200 Subject: [PATCH] More typing fixes. --- django_etebase/models.py | 1 + etebase_fastapi/routers/collection.py | 10 ++++++---- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/django_etebase/models.py b/django_etebase/models.py index 7725a19..fa56a95 100644 --- a/django_etebase/models.py +++ b/django_etebase/models.py @@ -56,6 +56,7 @@ class Collection(models.Model): @property def content(self) -> "CollectionItemRevision": + assert self.main_item is not None return self.main_item.content @property diff --git a/etebase_fastapi/routers/collection.py b/etebase_fastapi/routers/collection.py index 4825626..e20e955 100644 --- a/etebase_fastapi/routers/collection.py +++ b/etebase_fastapi/routers/collection.py @@ -107,6 +107,7 @@ class CollectionOut(CollectionCommon): def from_orm_context(cls: t.Type["CollectionOut"], obj: models.Collection, context: Context) -> "CollectionOut": member: models.CollectionMember = obj.members.get(user=context.user) collection_type = member.collectionType + assert obj.main_item is not None ret = cls( collectionType=collection_type and bytes(collection_type.uid), collectionKey=bytes(member.encryptionKey), @@ -299,8 +300,8 @@ def process_revisions_for_item(item: models.CollectionItem, revision_data: Colle revision.stoken = stoken revision.save() - for chunk in chunks_objs: - models.RevisionChunkRelation.objects.create(chunk=chunk, revision=revision) + for chunk2 in chunks_objs: + models.RevisionChunkRelation.objects.create(chunk=chunk2, revision=revision) return revision @@ -383,6 +384,7 @@ def item_create(item_model: CollectionItemIn, collection: models.Collection, val # We don't have to use select_for_update here because the unique constraint on current guards against # the race condition. But it's a good idea because it'll lock and wait rather than fail. current_revision = instance.revisions.filter(current=True).select_for_update().first() + assert current_revision is not None current_revision.current = None current_revision.save() @@ -523,8 +525,8 @@ def fetch_updates( new_stoken_obj = get_queryset_stoken(queryset) new_stoken = new_stoken_obj and new_stoken_obj.uid - stoken = stoken_rev and getattr(stoken_rev, "uid", None) - new_stoken = new_stoken or stoken + stoken_rev_uid = stoken_rev and getattr(stoken_rev, "uid", None) + new_stoken = new_stoken or stoken_rev_uid context = Context(user, prefetch) return CollectionItemListResponse(