Report hasn't been filed before.
What version of drizzle-orm are you using?
1.0.0-rc.1
What version of drizzle-kit are you using?
1.0.0-rc.1
Other packages
No response
Describe the Bug
Summary
customType resolves a codec by slicing the dataType() string at the first (. For a PostGIS polygon defined as geometry(Polygon, 4326), this slices to "geometry", which maps to the
point-only codec and runs parseGeometryXY on polygon EWKB. The codec then throws Error: Unsupported geometry type on every read.
Versions
drizzle-orm@1.0.0-rc.1
- Postgres + PostGIS
Repro
import { customType } from "drizzle-orm/pg-core";
export const polygon = customType<{ data: [number, number][][] }>({
dataType() {
return "geometry(Polygon, 4326)";
},
toDriver(value) { /* ST_GeomFromText(...) */ },
// no fromDriver, no codec
});
export const Geofence = pgTable("geofences", {
id: uuid().primaryKey(),
polygon: polygon("polygon").notNull(),
});
await db.select().from(Geofence); // throws
Where it happens
pg-core/columns/custom.js:
this.codec = resolvePgType(
config.customTypeParams.codec ??
this.sqlName.slice(0, Math.min(...[
this.sqlName.indexOf("("),
this.sqlName.indexOf("[")
].filter((e) => e !== -1)))
);
For "geometry(Polygon, 4326)" this becomes resolvePgType("geometry") → the geometry codec → parseGeometryXY, which only supports Points:
if ((geomType & 65535) === 1) { /* Point */ }
throw new Error("Unsupported geometry type");
Expected
The auto-inferred codec for a custom PostGIS type that isn't a Point should not crash — either:
- skip codec inference when the param substring doesn't have a 1:1 codec match for the actual geometry kind, or
- only auto-infer when the inferred codec key has a definition compatible with the column data, or
- document that
customType users must set codec explicitly when their dataType() starts with geometry(...).
Actual
at Module.parseEWKB (drizzle-orm/pg-core/columns/postgis_extension/utils.ts:46)
at parseGeometryXY (drizzle-orm/pg-core/codecs.ts:287)
at Object.eval (drizzle:jit-relational-query-mapper:82)
Workaround
Pass an explicit codec whose key has no entry in the codec map (so CodecsCollection.get returns undefined and no normalization runs):
export const polygon = customType<{ data: [number, number][][] }>({
dataType() { return "geometry(Polygon, 4326)"; },
codec: "polygon", // <- disables auto-inference; codecs["polygon"] is undefined
toDriver(value) { /* ... */ },
});
Worked fine on 1.0.0-beta.* because customType did not auto-resolve a codec.
Report hasn't been filed before.
What version of
drizzle-ormare you using?1.0.0-rc.1
What version of
drizzle-kitare you using?1.0.0-rc.1
Other packages
No response
Describe the Bug
Summary
customTyperesolves a codec by slicing thedataType()string at the first(. For a PostGIS polygon defined asgeometry(Polygon, 4326), this slices to"geometry", which maps to thepoint-only codec and runs
parseGeometryXYon polygon EWKB. The codec then throwsError: Unsupported geometry typeon every read.Versions
drizzle-orm@1.0.0-rc.1Repro
Where it happens
pg-core/columns/custom.js:For
"geometry(Polygon, 4326)"this becomesresolvePgType("geometry")→ thegeometrycodec →parseGeometryXY, which only supports Points:Expected
The auto-inferred codec for a custom PostGIS type that isn't a Point should not crash — either:
customTypeusers must setcodecexplicitly when theirdataType()starts withgeometry(...).Actual
Workaround
Pass an explicit
codecwhose key has no entry in the codec map (soCodecsCollection.getreturnsundefinedand no normalization runs):Worked fine on
1.0.0-beta.*becausecustomTypedid not auto-resolve a codec.