From 15988235f27673398416b244fd40aa39009a89f1 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Mon, 28 Dec 2020 08:42:48 +0200 Subject: [PATCH] Exclude unset fields so fix removedMemberships return value. --- etebase_fastapi/collection.py | 6 +++--- etebase_fastapi/msgpack.py | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/etebase_fastapi/collection.py b/etebase_fastapi/collection.py index 33f1d64..1c5ca14 100644 --- a/etebase_fastapi/collection.py +++ b/etebase_fastapi/collection.py @@ -176,8 +176,9 @@ def collection_list_common( context = Context(user, prefetch) data: t.List[CollectionOut] = [CollectionOut.from_orm_context(item, context) for item in result] + ret = CollectionListResponse(data=data, stoken=new_stoken, done=done) + stoken_obj = get_stoken_obj(stoken) - removedMemberships = None if stoken_obj is not None: # FIXME: honour limit? (the limit should be combined for data and this because of stoken) remed_qs = models.CollectionMemberRemoved.objects.filter(user=user, stoken__id__gt=stoken_obj.id) @@ -188,9 +189,8 @@ def collection_list_common( remed = remed_qs.values_list("collection__uid", flat=True) if len(remed) > 0: - removedMemberships = [{"uid": x} for x in remed] + ret.removedMemberships = [{"uid": x} for x in remed] - ret = CollectionListResponse(data=data, stoken=new_stoken, done=done, removedMemberships=removedMemberships) return MsgpackResponse(content=ret) diff --git a/etebase_fastapi/msgpack.py b/etebase_fastapi/msgpack.py index edffd7e..0c5cc30 100644 --- a/etebase_fastapi/msgpack.py +++ b/etebase_fastapi/msgpack.py @@ -24,7 +24,7 @@ class MsgpackResponse(Response): return b"" if isinstance(content, BaseModel): - content = content.dict() + content = content.dict(exclude_unset=True) return msgpack.packb(content, use_bin_type=True)