]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Update `TZDateTime` type decorator example to align with python docs
authorKevin Kirsche <kevin.kirsche@one.verizon.com>
Mon, 4 Dec 2023 18:25:24 +0000 (13:25 -0500)
committerFederico Caselli <cfederico87@gmail.com>
Mon, 4 Dec 2023 18:29:32 +0000 (19:29 +0100)
This change updates the `TZDateTime` type decorator to use the timezone awareness checks described in the Python documentation located here:

https://docs.python.org/3/library/datetime.html#determining-if-an-object-is-aware-or-naive

The specific lines state:

> A [`datetime`](https://docs.python.org/3/library/datetime.html#datetime.datetime) object `d` is aware if both of the following hold:
>
> `d.tzinfo is not None`
>
> `d.tzinfo.utcoffset(d)` does not return `None`
>
> Otherwise, `d` is naive.

Closes: #10719
Pull-request: https://github.com/sqlalchemy/sqlalchemy/pull/10719
Pull-request-sha: bb30cb3cfe57f326addec21a6cae5f81184c2e74

Change-Id: I1ac51c1ec2820c3f224a79b7af5057fe2b3a55e2

doc/build/core/custom_types.rst

index 6ae9e066ace7711f3843b485fe78a0f5f8dfbd9a..b9d8953b4e8c45a40f298f3683f785baadbeed5d 100644 (file)
@@ -156,7 +156,7 @@ denormalize::
 
         def process_bind_param(self, value, dialect):
             if value is not None:
-                if not value.tzinfo:
+                if not value.tzinfo or value.tzinfo.utcoffset(value) is None:
                     raise TypeError("tzinfo is required")
                 value = value.astimezone(datetime.timezone.utc).replace(tzinfo=None)
             return value