Report the CrateDB type reflection could not resolve - #301
Draft
florinutz wants to merge 1 commit into
Draft
Conversation
|
Important Review skippedAuto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Plus Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
florinutz
force-pushed
the
flo/292-numeric-type
branch
from
August 31, 2026 17:40
2bc3cec to
6206a9e
Compare
A column whose CrateDB type the dialect cannot represent reflects as `UnresolvedType`, which still reads and, asked for DDL, raises `CompileError` naming the type, the table and the column, where the previous `sqltypes.UserDefinedType` default raised a bare `AttributeError` from inside SQLAlchemy. `geo_point` and `geo_shape` resolve to the `Geopoint` and `Geoshape` types the package already offers. An array type name resolves to an `ARRAY` of whatever the name without its `_array` suffix resolves to, replacing a fixed list of sixteen names; `object_array` keeps its own entry for the mutation tracking `ObjectArray` carries.
florinutz
force-pushed
the
flo/295-type-map
branch
from
August 31, 2026 17:48
88f526f to
9805faf
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Reflecting a table whose column type the dialect does not know produced
sqlalchemy.types.UserDefinedType— the abstract base class, missingget_col_spec(). Reflection appeared to succeed; emitting DDL from the reflected table then died withAttributeError: 'UserDefinedType' object has no attribute 'get_col_spec', naming neither the column nor the type.sys.summitsreproduces it: itscoordinatescolumn is ageo_point, and the package has exportedGeopointall along without registering it in the map.Closes #295.
Based on
flo/292-numeric-typerather thanmain, since both branches touchTYPES_MAPand the type compiler, and #292 lands thenumericentry the array derivation here covers asnumeric_array. Retarget tomainto review the two together.Root cause
_resolve_typereturnedTYPES_MAP.get(type_, sqltypes.UserDefinedType). That default is abstract only by a missing method rather than by ABC, so SQLAlchemy instantiates it, andSELECTworks becauseresult_processorreturnsNone. Only the type compiler (CreateTable,sa.cast()) reaches the missing method, with a traceback pointing into SQLAlchemy internals.Arrays were a fixed list of sixteen keys, and CrateDB forms an array type name as
<element>_array, so any name off the list fell through the same hole —timestamp without time zone_arrayamong them, while both its scalar and itswith time zonesibling were mapped.Fix
UnresolvedTypecarries the CrateDB type name reflection could not resolve. Such a column still reads, andCrateTypeCompilerrefuses to compile it:The issue proposes
sqltypes.NullType, whose only message is "Can't generate DDL for NullType(); did you forget to specify a type on this Column?" — nothing was forgotten, and no CrateDB type is named.UnresolvedTypeexists to carry that name, and is exported for callers who would rather testisinstance(column.type, UnresolvedType)than skip whole tables.The refusal lives in the type compiler rather than in
get_col_spec, because SQLAlchemy'sStrSQLTypeCompilercallsget_col_spectoo;str(column.type)keeps working from 1.4 onwards and yields the CrateDB type name.geo_pointandgeo_shapemap to theGeopointandGeoshapetypes already in the package. Array names are derived: strip one_array, resolve the rest, wrap inARRAY— replacing the fixed list, whose sixteen entries render identically to what derivation produces. Onlyobject_arraykeeps an entry, for the mutation trackingObjectArraycarries. Two shapes stay unresolved and report the column's own type name: an array whose element is unresolved (ip_array), and an array of arrays, which SQLAlchemy'sARRAYcannot hold. A derivedARRAYconverts no values, like the entries it replaces, sincesqlalchemy.types.ARRAYhas no processors of its own.Type names arrive from
information_schema.columns.data_type, which CrateDB emits lowercase for all 27 distinct values a stock 6.4.1 reports.Out of scope: reflection still selects only
column_nameanddata_type, so type parameters are lost — a reflectedVARCHAR(10)is unbounded, andFLOAT_VECTOR(3)andNUMERIC(10, 2)still refuse DDL for want of theirs.Tests
tests/reflection_test.py, new — nothing coveredTYPES_MAPor_resolve_typebefore: rendered DDL for every array name the fixed list carried plus the ones derivation adds; every mapped type as the element of its array form, walked overTYPES_MAPitself; refusal naming type, table and column for an unresolvable scalar, an unresolvable element, and arrays two and three deep; printing, selecting and one log record under the column's own type name; live,sys.summitsreflected and compiled back to DDL. Green on SQLAlchemy 1.3.24, 1.4.54, 2.0.52 and 2.1.0b3.