Skip to content

fix!: Fix SQLAlchemy ARRAY dimensions and Enum labels, support TypeDecorator - #147

Merged
FBruzzesi merged 6 commits into
mainfrom
fix/sqlalchemy-types
Nov 21, 2026
Merged

FBruzzesi merged 6 commits into
mainfrom
fix/sqlalchemy-types

Conversation

@FBruzzesi

Copy link
Copy Markdown
Owner

Summary

Fixes two wrong mappings in SQLAlchemyTypeStep and adds support for types that used to raise.

  • ARRAY(dimensions=N): dimensions is the nesting depth, not a length. ARRAY(Integer, dimensions=2) now gives List(List(Int32)) instead of Array(Int32, shape=(2,)).
  • Enum: categories now come from Enum.enums, the labels SQLAlchemy stores. By default those are the member names; with values_callable they are the member values. Before, an enum class always gave its member values, which didn't match what is stored in the table.
  • TypeDecorator: parsed as its implementation type (impl), so custom types and PickleType no longer raise. Column metadata still applies, e.g. a precision override on a decorator over Numeric.
  • PostgreSQL types: INTERVAL maps to Duration; INET, CIDR and MACADDR map to String.
  • Refactor: removed SupportedSQLAlchemyType, _SUPPORTED_SQLALCHEMY_TYPES and _is_supported_sqlalchemy_type. They repeated the isinstance chain only so the last line could assume "by exclusion it is ARRAY". ARRAY now has its own branch and parse ends with return None. is_sequence_of and is_sequence_but_not_str in _utils.py had no other users and are deleted.
SQLAlchemy type Before After
ARRAY(Integer, dimensions=2) Array(Int32, shape=(2,)) List(List(Int32))
Enum(Color) with Color.RED = "r" Enum(categories=['r', ...]) Enum(categories=['RED', ...])
TypeDecorator with impl = String(20) NotImplementedError String
PickleType() NotImplementedError Binary
postgresql.INTERVAL() NotImplementedError Duration
postgresql.INET() / CIDR() / MACADDR() NotImplementedError String

Breaking changes

  • ARRAY columns with dimensions set now give nested Lists. Columns without dimensions are unchanged (List).
  • Enum columns built from an enum class whose member names differ from their values now give the names. Plain string enums (Enum("a", "b")) and classes that use values_callable are unchanged.

@FBruzzesi
FBruzzesi merged commit 85a3b65 into main Nov 21, 2026
13 checks passed
@FBruzzesi
FBruzzesi deleted the fix/sqlalchemy-types branch November 21, 2026 20:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant