Skip to content
This repository has been archived by the owner on May 14, 2024. It is now read-only.

Commit

Permalink
fix: remove custom parse_utc_iso8601_datetime which doesn't handle mi…
Browse files Browse the repository at this point in the history
…ssing microseconds

Gave a test failure on CI with the string '2023-07-24T00:24:05+00:00'
  • Loading branch information
bradenmacdonald authored and Agrendalath committed Aug 11, 2023
1 parent 9a92cf1 commit 2ab8b15
Show file tree
Hide file tree
Showing 7 changed files with 4 additions and 28 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ Change Log
Unreleased
~~~~~~~~~~

*
* Removed custom datetime parser in favor of ``datetime.fromisoformat`` which is more robust.

[1.4.0] - 2023-08-07
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Expand Down
24 changes: 3 additions & 21 deletions blockstore/apps/bundles/store.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
import json
import logging
import mimetypes
import pytz

from django.core.files.base import ContentFile, File
from django.dispatch import Signal
Expand Down Expand Up @@ -317,7 +316,7 @@ def get(self, bundle_uuid: UUID, snapshot_digest: bytes) -> Snapshot:
bundle_uuid, snapshot_json.get('links', {})
),
hash_digest=bytes_from_hex_str(snapshot_json['hash_digest']),
created_at=parse_utc_iso8601_datetime(snapshot_json['created_at']),
created_at=datetime.fromisoformat(snapshot_json['created_at']),
)

def create(self, bundle_uuid, paths_to_files, links=None):
Expand Down Expand Up @@ -476,8 +475,8 @@ def get(self, draft_uuid: UUID) -> StagedDraft:
base_snapshot=base_snapshot,
files_to_overwrite=FileInfo.from_json_dict(draft_summary_json['files_to_overwrite']),
links_to_overwrite=links_to_overwrite,
created_at=parse_utc_iso8601_datetime(draft_summary_json['created_at']),
updated_at=parse_utc_iso8601_datetime(draft_summary_json['updated_at']),
created_at=datetime.fromisoformat(draft_summary_json['created_at']),
updated_at=datetime.fromisoformat(draft_summary_json['updated_at']),
)

def create(self, draft_uuid: UUID, bundle_uuid: UUID, name: str,
Expand Down Expand Up @@ -839,23 +838,6 @@ def create_hash(start_data=b''):
return blake2b(start_data, digest_size=20)


def parse_utc_iso8601_datetime(datetime_str):
"""
Create a UTC datetime from a str generated by calling datetime.isoformat()
Python's datetime module is incapable of parsing the ISO 8601 string output
that it itself produces (it can't do timezones with ":" in them), so we need
to only parse the part before that and then manually add UTC timezone
information into it. This is a hack -- it will ignore whatever timezone is
really there and force it to be interpreted as UTC.
This hack should not be necessary once we move to Python 3.7 and can be
replaced with datetime.fromisoformat().
"""
parsed_dt = datetime.strptime(datetime_str, r'%Y-%m-%dT%H:%M:%S.%f+00:00')
return pytz.utc.localize(parsed_dt).astimezone(timezone.utc)


def bytes_from_hex_str(hex_str):
"""Return bytes given a hexidecimal string representation of binary data."""
if hex_str is None:
Expand Down
1 change: 0 additions & 1 deletion requirements/base.in
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,4 @@ edx-auth-backends
edx-django-release-util
edx-django-utils
mysqlclient
pytz
sqlparse
1 change: 0 additions & 1 deletion requirements/base.txt
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,6 @@ python3-openid==3.2.0
# via social-auth-core
pytz==2023.3
# via
# -r requirements/base.in
# django
# djangorestframework
# drf-yasg
Expand Down
2 changes: 0 additions & 2 deletions requirements/local.txt
Original file line number Diff line number Diff line change
Expand Up @@ -315,8 +315,6 @@ python3-openid==3.2.0
# social-auth-core
pytz==2023.3
# via
# -r requirements/docs.txt
# -r requirements/test.txt
# babel
# django
# djangorestframework
Expand Down
1 change: 0 additions & 1 deletion requirements/production.txt
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,6 @@ python3-openid==3.2.0
# social-auth-core
pytz==2023.3
# via
# -r requirements/base.txt
# django
# djangorestframework
# drf-yasg
Expand Down
1 change: 0 additions & 1 deletion requirements/test.txt
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,6 @@ python3-openid==3.2.0
# social-auth-core
pytz==2023.3
# via
# -r requirements/base.txt
# django
# djangorestframework
# drf-yasg
Expand Down

0 comments on commit 2ab8b15

Please sign in to comment.