Fix chunk handling.

master
Tom Hacohen 4 years ago
parent a3ae769a2c
commit e7721e8fe5

@ -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):

Loading…
Cancel
Save