Skip to content

Commit

Permalink
Types: Unlock supporting timezone-aware DateTime fields
Browse files Browse the repository at this point in the history
  • Loading branch information
amotl committed Jan 15, 2024
1 parent 07bba7b commit 2eca67a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 6 deletions.
4 changes: 0 additions & 4 deletions src/sqlalchemy_cratedb/dialect.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,10 @@ def process(value):

class DateTime(sqltypes.DateTime):

TZ_ERROR_MSG = "Timezone aware datetime objects are not supported"

def bind_processor(self, dialect):
def process(value):
if value is not None:
assert isinstance(value, datetime)
if value.tzinfo is not None:
raise TimezoneUnawareException(DateTime.TZ_ERROR_MSG)
return value.strftime('%Y-%m-%dT%H:%M:%S.%fZ')
return value
return process
Expand Down
3 changes: 1 addition & 2 deletions tests/datetime_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,8 @@ def test_date_can_handle_datetime(self):
]
self.session.query(self.Character).first()

def test_date_cannot_handle_tz_aware_datetime(self):
def test_date_can_handle_tz_aware_datetime(self):
character = self.Character()
character.name = "Athur"
character.timestamp = datetime(2009, 5, 13, 19, 19, 30, tzinfo=CST())
self.session.add(character)
self.assertRaises(DBAPIError, self.session.commit)

0 comments on commit 2eca67a

Please sign in to comment.