diff options
| -rw-r--r-- | doc/build/changelog/unreleased_14/7943.rst | 9 | ||||
| -rw-r--r-- | lib/sqlalchemy/dialects/postgresql/base.py | 4 | ||||
| -rw-r--r-- | test/dialect/postgresql/test_types.py | 4 |
3 files changed, 17 insertions, 0 deletions
diff --git a/doc/build/changelog/unreleased_14/7943.rst b/doc/build/changelog/unreleased_14/7943.rst new file mode 100644 index 000000000..e5ed12e7f --- /dev/null +++ b/doc/build/changelog/unreleased_14/7943.rst @@ -0,0 +1,9 @@ +.. change:: + :tags: bug, postgresql + :tickets: 7943 + + Implemented :attr:`_postgresql.UUID.python_type` attribute for the + :class:`_postgresql.UUID` type object. The attribute will return either + ``str`` or ``uuid.UUID`` based on the :paramref:`_postgresql.UUID.as_uuid` + parameter setting. Previously, this attribute was unimplemented. Pull + request courtesy Alex Grönholm.
\ No newline at end of file diff --git a/lib/sqlalchemy/dialects/postgresql/base.py b/lib/sqlalchemy/dialects/postgresql/base.py index 6c3bc4e7c..5d1298cf7 100644 --- a/lib/sqlalchemy/dialects/postgresql/base.py +++ b/lib/sqlalchemy/dialects/postgresql/base.py @@ -1815,6 +1815,10 @@ class UUID(sqltypes.TypeEngine): return process + @property + def python_type(self): + return _python_UUID if self.as_uuid else str + PGUuid = UUID diff --git a/test/dialect/postgresql/test_types.py b/test/dialect/postgresql/test_types.py index a59dd0ac7..8c4bb7fe7 100644 --- a/test/dialect/postgresql/test_types.py +++ b/test/dialect/postgresql/test_types.py @@ -2832,6 +2832,10 @@ class UUIDTest(fixtures.TestBase): ) eq_(v1.fetchone()[0], value1) + def test_python_type(self): + eq_(postgresql.UUID(as_uuid=True).python_type, uuid.UUID) + eq_(postgresql.UUID(as_uuid=False).python_type, str) + class HStoreTest(AssertsCompiledSQL, fixtures.TestBase): __dialect__ = "postgresql" |
