Skip to content

Commit 6ddf95c

Browse files
authored
Workaround SQLAlchemy 2.0.42 DOMAIN type adaptation regression (#435)
* Bugfix * Added CHANGES.rst entry * Comment fix
1 parent 4d4c84c commit 6ddf95c

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

CHANGES.rst

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
Version history
22
===============
33

4+
**UNRELEASED**
5+
- Fix Postgres ``DOMAIN`` adaptation regression introduced in SQLAlchemy 2.0.42 (PR by @sheinbergon)
6+
47
**3.1.1**
58

69
- Fallback ``NotImplemented`` errors encountered when accessing ``python_type`` for

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ classifiers = [
2929
]
3030
requires-python = ">=3.9"
3131
dependencies = [
32-
"SQLAlchemy >= 2.0.29,<2.0.42",
32+
"SQLAlchemy >= 2.0.29",
3333
"inflect >= 4.0.0",
3434
"importlib_metadata; python_version < '3.10'",
3535
"stdlib-list; python_version < '3.10'"

src/sqlacodegen/generators.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -718,6 +718,20 @@ def get_adapted_type(self, coltype: Any) -> Any:
718718
if coltype.schema:
719719
kw["schema"] = coltype.schema
720720

721+
# Hack to fix Postgres DOMAIN type adaptation, broken as of SQLAlchemy 2.0.42
722+
# For additional information - https://github.com/agronholm/sqlacodegen/issues/416#issuecomment-3417480599
723+
if supercls is DOMAIN:
724+
if coltype.default:
725+
kw["default"] = coltype.default
726+
if coltype.constraint_name is not None:
727+
kw["constraint_name"] = coltype.constraint_name
728+
if coltype.not_null:
729+
kw["not_null"] = coltype.not_null
730+
if coltype.check is not None:
731+
kw["check"] = coltype.check
732+
if coltype.create_type:
733+
kw["create_type"] = coltype.create_type
734+
721735
try:
722736
new_coltype = coltype.adapt(supercls)
723737
except TypeError:

0 commit comments

Comments
 (0)