Fix chunk handling.

This commit is contained in:
Tom Hacohen 2020-12-27 18:12:16 +02:00
parent a3ae769a2c
commit e7721e8fe5

View File

@ -50,13 +50,15 @@ class CollectionItemRevisionInOut(BaseModel):
def from_orm_context( def from_orm_context(
cls: t.Type["CollectionItemRevisionInOut"], obj: models.CollectionItemRevision, context: Context cls: t.Type["CollectionItemRevisionInOut"], obj: models.CollectionItemRevision, context: Context
) -> "CollectionItemRevisionInOut": ) -> "CollectionItemRevisionInOut":
chunk_obj = obj.chunks_relation.get().chunk chunks = []
if context.prefetch == "auto": for chunk_relation in obj.chunks_relation.all():
with open(chunk_obj.chunkFile.path, "rb") as f: chunk_obj = chunk_relation.chunk
chunks = chunk_obj.uid, f.read() if context.prefetch == "auto":
else: with open(chunk_obj.chunkFile.path, "rb") as f:
chunks = (chunk_obj.uid,) chunks.append((chunk_obj.uid, f.read()))
return cls(uid=obj.uid, meta=obj.meta, deleted=obj.deleted, chunks=[chunks]) else:
chunks.append((chunk_obj.uid,))
return cls(uid=obj.uid, meta=obj.meta, deleted=obj.deleted, chunks=chunks)
class CollectionItemCommon(BaseModel): class CollectionItemCommon(BaseModel):