From e7721e8fe52fce7667017acafee7a2c0bd8a7143 Mon Sep 17 00:00:00 2001 From: Tom Hacohen Date: Sun, 27 Dec 2020 18:12:16 +0200 Subject: [PATCH] Fix chunk handling. --- etebase_fastapi/collection.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/etebase_fastapi/collection.py b/etebase_fastapi/collection.py index 7679ed6..229b8c4 100644 --- a/etebase_fastapi/collection.py +++ b/etebase_fastapi/collection.py @@ -50,13 +50,15 @@ class CollectionItemRevisionInOut(BaseModel): def from_orm_context( cls: t.Type["CollectionItemRevisionInOut"], obj: models.CollectionItemRevision, context: Context ) -> "CollectionItemRevisionInOut": - chunk_obj = obj.chunks_relation.get().chunk - if context.prefetch == "auto": - with open(chunk_obj.chunkFile.path, "rb") as f: - chunks = chunk_obj.uid, f.read() - else: - chunks = (chunk_obj.uid,) - return cls(uid=obj.uid, meta=obj.meta, deleted=obj.deleted, chunks=[chunks]) + chunks = [] + for chunk_relation in obj.chunks_relation.all(): + chunk_obj = chunk_relation.chunk + if context.prefetch == "auto": + with open(chunk_obj.chunkFile.path, "rb") as f: + chunks.append((chunk_obj.uid, f.read())) + else: + chunks.append((chunk_obj.uid,)) + return cls(uid=obj.uid, meta=obj.meta, deleted=obj.deleted, chunks=chunks) class CollectionItemCommon(BaseModel):