Skip to content

fix(uploader): TypeError between offset-native and offset-aware datetimes#1082

Open
mango-cube wants to merge 1 commit into
microsoftgraph:mainfrom
mango-cube:bugfix/large-file-upload-typeerror
Open

fix(uploader): TypeError between offset-native and offset-aware datetimes#1082
mango-cube wants to merge 1 commit into
microsoftgraph:mainfrom
mango-cube:bugfix/large-file-upload-typeerror

Conversation

@mango-cube
Copy link
Copy Markdown

@mango-cube mango-cube commented May 25, 2026

The error:

(.venv) C:\DeveloperFiles\Repos\reporting\bitbucket-reporter>python test.py
Traceback (most recent call last):
  File "C:\DeveloperFiles\Repos\reporting\bitbucket-reporter\test.py", line 21, in <module>
    asyncio.run(uploader.upload_large_file(file_to_upload='mango_test.txt', destination_path="root:/Reports/mango.txt:"))
  File "C:\Users\mango\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 190, in run
    return runner.run(main)
           ^^^^^^^^^^^^^^^^
  File "C:\Users\mango\AppData\Local\Programs\Python\Python311\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\mango\AppData\Local\Programs\Python\Python311\Lib\asyncio\base_events.py", line 654, in run_until_complete
    return future.result()
           ^^^^^^^^^^^^^^^
  File "C:\DeveloperFiles\Repos\reporting\bitbucket-reporter\sharepoint_uploader.py", line 110, in upload_large_file
    upload_result = await task.upload(progress_callback)
                    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\DeveloperFiles\Repos\reporting\bitbucket-reporter\.venv\Lib\site-packages\msgraph_core\tasks\large_file_upload.py", line 91, in upload
    if self.upload_session_expired(self.upload_session):
       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "c:\DeveloperFiles\Repos\reporting\bitbucket-reporter\.venv\Lib\site-packages\msgraph_core\tasks\large_file_upload.py", line 81, in upload_session_expired
    interval = now - then
               ~~~~^~~~~~
TypeError: can't subtract offset-naive and offset-aware datetimes

@mango-cube mango-cube requested a review from a team as a code owner May 25, 2026 06:58
@sonarqubecloud
Copy link
Copy Markdown

Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Fixes a TypeError in LargeFileUploadTask.upload_session_expired caused by subtracting offset-aware and offset-naive datetime values when validating whether an upload session has expired.

Changes:

  • Forces expiration_date_time datetimes to be treated as UTC to avoid naive/aware subtraction errors.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines 75 to 80
if isinstance(expiry, str):
then = datetime.strptime(expiry, "%Y-%m-%dT%H:%M:%S")
elif isinstance(expiry, datetime):
then = expiry
then = expiry.replace(tzinfo=timezone.utc)
else:
raise ValueError("Expiry is not a string or datetime")
Comment on lines 74 to +78
raise ValueError("Expiry is None")
if isinstance(expiry, str):
then = datetime.strptime(expiry, "%Y-%m-%dT%H:%M:%S")
elif isinstance(expiry, datetime):
then = expiry
then = expiry.replace(tzinfo=timezone.utc)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants