Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error: Unsupported PostGIS modifier --> ? #47

Open
disarticulate opened this issue Jul 31, 2022 · 4 comments
Open

Error: Unsupported PostGIS modifier --> ? #47

disarticulate opened this issue Jul 31, 2022 · 4 comments
Labels

Comments

@disarticulate
Copy link

Summary

what is _ Error: Unsupported PostGIS modifier _ in

export const getGISTypeDetails = (modifier: number): GISTypeDetails => {
  const allZeroesHopefully = modifier >> 24;
  if (allZeroesHopefully !== 0) {
    throw new Error("Unsupported PostGIS modifier");
  }
  [...]

Steps to reproduce

Versioning (latest & greatest?)

Node.js version:     v18.6.0 on linux x64

postgraphile -V 4.12.11

CREATE EXTENSION IF NOT EXISTS postgis SCHEMA public VERSION "3.2.1";

PostgreSQL 14.4 (Debian 14.4-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

Error:

graphql_1                  | Error: Unsupported PostGIS modifier
graphql_1                  |     at exports.getGISTypeDetails (/usr/local/lib/node_modules/@graphile/postgis/dist/utils.js:7:15)
graphql_1                  |     at getGisType (/usr/local/lib/node_modules/@graphile/postgis/dist/PostgisRegisterTypesPlugin.js:117:41)
graphql_1                  |     at /usr/local/lib/node_modules/@graphile/postgis/dist/PostgisRegisterTypesPlugin.js:206:20
graphql_1                  |     at Object.getGqlTypeByTypeIdAndModifier (/usr/local/lib/node_modules/postgraphile/node_modules/graphile-build-pg/node8plus/plugins/PgTypesPlugin.js:816:26)
graphql_1                  |     at fieldWithHooks.pgFieldIntrospection (/usr/local/lib/node_modules/postgraphile/node_modules/graphile-build-pg/node8plus/plugins/PgColumnsPlugin.js:106:30)
graphql_1                  |     at fieldWithHooks (/usr/local/lib/node_modules/postgraphile/node_modules/graphile-build/node8plus/makeNewBuild.js:483:29)
graphql_1                  |     at /usr/local/lib/node_modules/postgraphile/node_modules/graphile-build-pg/node8plus/plugins/PgColumnsPlugin.js:97:22
graphql_1                  |     at Array.reduce (<anonymous>)
graphql_1                  |     at /usr/local/lib/node_modules/postgraphile/node_modules/graphile-build-pg/node8plus/plugins/PgColumnsPlugin.js:86:44
graphql_1                  |     at SchemaBuilder.applyHooks (/usr/local/lib/node_modules/postgraphile/node_modules/graphile-build/node8plus/SchemaBuilder.js:264:20)

Expected results

Plugin loads

Actual results

Plugin "unsupported"

Additional context

Recently built postgis with postgresql database. Far as I can tell, everything is up to date. The error appears related to the specific code bit, without any comment on the context of the allZeroesHopefully.

Definitely willing to debug further if guidance is provided.

@benjie
Copy link
Member

benjie commented Aug 1, 2022

Weird...

const allZeroesHopefully = modifier >> 24;

Should that have been 32? The type modifier is 4 bytes (32 bits); I wonder why we always expect the first byte to be zero.

Here's the comment where we detail the reverse engineering of the type modifier value.

postgis/src/utils.ts

Lines 10 to 14 in babcd58

// Ref: https://github.com/postgis/postgis/blob/2.5.2/liblwgeom/liblwgeom.h.in#L156-L173
// #define TYPMOD_GET_SRID(typmod) ((((typmod) & 0x0FFFFF00) - ((typmod) & 0x10000000)) >> 8)
// #define TYPMOD_GET_TYPE(typmod) ((typmod & 0x000000FC)>>2)
// #define TYPMOD_GET_Z(typmod) ((typmod & 0x00000002)>>1)
// #define TYPMOD_GET_M(typmod) (typmod & 0x00000001)

And the comment in the PostGIS source:

/**
* Macros for manipulating the 'typemod' int. An int32_t used as follows:
* Plus/minus = Top bit.
* Spare bits = Next 2 bits.
* SRID = Next 21 bits.
* TYPE = Next 6 bits.
* ZM Flags = Bottom 2 bits.
*/

Maybe it's that you're using a different SRID than we expect? I only tested it with 4326.

@disarticulate
Copy link
Author

disarticulate commented Aug 3, 2022

I believe it's the SRID.

DROP SCHEMA IF EXISTS test CASCADE;
CREATE SCHEMA test;

DROP TABLE IF EXISTS test.test;
CREATE TABLE IF NOT EXISTS test.test
(
    geompoint geometry(Point,96826),
    geomline geometry(LineString,96826),
    geom geometry(Polygon,96826),
    geompointz geometry(PointZ,96826),
    geomlinez geometry(LineStringZ,96826),
    geomz geometry(PolygonZ,96826)
);
/* FAILS:
2022-08-03T20:36:40.951Z graphile-build:warn Error: Unsupported PostGIS modifier
graphql-test_1             |     at exports.getGISTypeDetails (/app/node_modules/@graphile/postgis/dist/utils.js:7:15)
graphql-test_1             |     at getGisType (/app/node_modules/@graphile/postgis/dist/PostgisRegisterTypesPlugin.js:117:41)
graphql-test_1             |     at /app/node_modules/@graphile/postgis/dist/PostgisRegisterTypesPlugin.js:206:20
graphql-test_1             |     at getGqlTypeByTypeIdAndModifier (/app/node_modules/graphile-build-pg/node8plus/plugins/PgTypesPlugin.js:816:26)
graphql-test_1             |     at Object.getGqlInputTypeByTypeIdAndModifier (/app/node_modules/graphile-build-pg/node8plus/plugins/PgTypesPlugin.js:847:7)
graphql-test_1             |     at /app/node_modules/graphile-build-pg/node8plus/plugins/PgColumnsPlugin.js:177:243
graphql-test_1             |     at Array.reduce (<anonymous>)
graphql-test_1             |     at /app/node_modules/graphile-build-pg/node8plus/plugins/PgColumnsPlugin.js:162:44
graphql-test_1             |     at SchemaBuilder.applyHooks (/app/node_modules/graphile-build/node8plus/SchemaBuilder.js:264:20)
graphql-test_1             |     at fields (/app/node_modules/graphile-build/node8plus/makeNewBuild.js:566:40)
graphql-test_1             | A serious error occurred when building the initial schema. Exiting because `retryOnInitFail` is not set. Error details:
*/

Currently [email protected] has srid in spatial_ref_sys up to 104853 which are esri. 21 bits would go to 2097152

after the quoted lines, it says:

/**
* Maximum allowed SRID value in serialized geometry.
* Currently we are using 21 bits (2097152) of storage for SRID.
*/
#define SRID_MAXIMUM @SRID_MAX@

@benjie
Copy link
Member

benjie commented Aug 3, 2022

Yeah definitely sounds like it’s the first byte issue then. Have a go at editing the logic linked above and see if that fixes it; hopefully it’s a simple fix 🤞

@disarticulate
Copy link
Author

so just a quick console log, I'm getting a type modifier 24787460 failing.

Plugging that in: ```
24787460 >> 24 = 1
24787460 >> 25 = 0
24778460 >> 32 = 24778460

Gonna assume it's the offbyonerror and run some tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants