]> git.ipfire.org Git - thirdparty/sqlalchemy/sqlalchemy.git/commitdiff
Update type_decorator example to align with python docs 10719/head
authorKevin Kirsche <kevin.kirsche@one.verizon.com>
Thu, 30 Nov 2023 14:59:11 +0000 (09:59 -0500)
committerGitHub <noreply@github.com>
Thu, 30 Nov 2023 14:59:11 +0000 (09:59 -0500)
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` object `d` is aware if both of the following hold:
>
>```python
d.tzinfo is not None
d.tzinfo.utcoffset(d) does not return None
```
>
>Otherwise, `d` is naive.

doc/build/core/custom_types.rst

index 6ae9e066ace7711f3843b485fe78a0f5f8dfbd9a..3642314c08ef6e0e561676c6d5d23d966c677033 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 and not value.tzinfo.utcoffset(value):
                     raise TypeError("tzinfo is required")
                 value = value.astimezone(datetime.timezone.utc).replace(tzinfo=None)
             return value