|
2 | 2 |
|
3 | 3 | import asyncio |
4 | 4 | import logging |
| 5 | +from collections.abc import Awaitable, Callable |
5 | 6 | from datetime import datetime, timezone |
6 | | -from collections.abc import Callable, Awaitable |
7 | 7 |
|
8 | 8 | from aiohttp import ClientSession |
| 9 | +from mashumaro.exceptions import MissingField |
9 | 10 |
|
10 | 11 | from onedrive_personal_sdk.clients.base import OneDriveBaseClient |
11 | | -from onedrive_personal_sdk.const import GRAPH_BASE_URL, HttpMethod, ConflictBehavior |
| 12 | +from onedrive_personal_sdk.const import GRAPH_BASE_URL, ConflictBehavior, HttpMethod |
12 | 13 | from onedrive_personal_sdk.exceptions import ( |
| 14 | + ExpectedRangeNotInBufferError, |
13 | 15 | HashMismatchError, |
14 | 16 | HttpRequestException, |
15 | 17 | OneDriveException, |
16 | | - ExpectedRangeNotInBufferError, |
17 | 18 | UploadSessionExpired, |
18 | 19 | ) |
19 | 20 | from onedrive_personal_sdk.models.items import File |
@@ -84,8 +85,8 @@ async def upload( |
84 | 85 | while retries < self._max_retries: |
85 | 86 | try: |
86 | 87 | return await self.start_upload(upload_session, validate_hash) |
87 | | - except UploadSessionExpired: |
88 | | - _LOGGER.debug("Session expired/not found, restarting") |
| 88 | + except (UploadSessionExpired, MissingField): |
| 89 | + _LOGGER.debug("Session expired/not found/broken, restarting") |
89 | 90 | self._buffer = UploadBuffer() |
90 | 91 | self._upload_result = LargeFileChunkUploadResult( |
91 | 92 | datetime.now(timezone.utc), ["0-"] |
@@ -131,8 +132,9 @@ async def start_upload( |
131 | 132 | if self._buffer.length >= self._upload_chunk_size: |
132 | 133 | uploaded_chunks = 0 |
133 | 134 | while ( |
134 | | - self._buffer.length - uploaded_chunks * UPLOAD_CHUNK_SIZE |
135 | | - ) > self._upload_chunk_size: # Loop in case the buffer is >= UPLOAD_CHUNK_SIZE * 2 |
| 135 | + (self._buffer.length - uploaded_chunks * UPLOAD_CHUNK_SIZE) |
| 136 | + > self._upload_chunk_size |
| 137 | + ): # Loop in case the buffer is >= UPLOAD_CHUNK_SIZE * 2 |
136 | 138 | slice_start = uploaded_chunks * self._upload_chunk_size |
137 | 139 | try: |
138 | 140 | chunk_result = await self._async_upload_chunk( |
|
0 commit comments