benoitdm-oslandia / pg_featureserv

Apache License 2.0
1 stars 0 forks source link

Bug - POST, PUT and PATCH fail with generic Geometry columns (nil pointer deference) #165

Closed azarz closed 1 year ago

azarz commented 1 year ago

The only supported postGIS tables are those with a specific geometry type in the table definition, such as:

CREATE TABLE toto
(
    id integer primary key,
    geom geometry(Point, 4326),
    ...
);

Both...

CREATE TABLE toto
(
    id integer primary key,
    geom geometry(Geometry, 4326),
    ...
);

...and...

CREATE TABLE toto
(
    id integer primary key,
    geom geometry,
    ...
);

...don't work with pg_featureserv. The former results in nil pointer deference, and the latter makes the table not scannable by the catalog.

dr-jts commented 1 year ago

As per the documentation, table require geometry columns to have a defined SRID. So that's why the 3rd example doesn't publish.

I have tried the second example, and haven't had any problem in creating a table with a geometry column defined like this:

geom geometry(Geometry, 4326)

What is the query and error message that you see? (Run in --debug mode for the most verbose log).

azarz commented 1 year ago

With my table defined as

CREATE TABLE toto
(
    id integer primary key,
    geom geometry(Geometry, 4326)
);

I tried GET requests and they seem to work, however all other request types fail, with a nil pointer deference error on the server side.

e.g. curl -X POST "http://localhost:9000/collections/toto/items" -H "accept: */*" -H "Content-Type: application/json" -d "{\"geometry\":{\"coordinates\":[[-70.88461956597838,47.807897059236495],[-70.88461956597838,47.807897059236495]],\"type\":\"Linestring\"},\"properties\":{},\"type\":\"Feature\"}"

curl: (52) Empty reply from server Server side, with the --debug mode enabled:

DEBU[0012] 127.0.0.1:57678 POST /collections/toto/items 
DEBU[0012] Load table catalog:
SELECT
Format('%s.%s', n.nspname, c.relname) AS id,
n.nspname AS schema,
c.relname AS table,
coalesce(d.description, '') AS description,
a.attname AS geometry_column,
postgis_typmod_srid(a.atttypmod) AS srid,
postgis_typmod_type(a.atttypmod) AS geometry_type,
coalesce(ia.attname, '') AS id_column,
(
SELECT array_agg(ARRAY[sa.attname, st.typname, coalesce(da.description,''), sa.attnum::text, sa.attnotnull]::text[] ORDER BY sa.attnum)
FROM pg_attribute sa
JOIN pg_type st ON sa.atttypid = st.oid
LEFT JOIN pg_description da ON (c.oid = da.objoid and sa.attnum = da.objsubid)
WHERE sa.attrelid = c.oid
AND sa.attnum > 0
AND NOT sa.attisdropped
AND st.typname NOT IN ('geometry', 'geography')
) AS props
FROM pg_class c
JOIN pg_namespace n ON (c.relnamespace = n.oid)
JOIN pg_attribute a ON (a.attrelid = c.oid)
JOIN pg_type t ON (a.atttypid = t.oid)
LEFT JOIN pg_description d ON (c.oid = d.objoid AND d.objsubid = 0)
LEFT JOIN pg_index i ON (c.oid = i.indrelid AND i.indisprimary
AND i.indnatts = 1)
LEFT JOIN pg_attribute ia ON (ia.attrelid = i.indexrelid)
LEFT JOIN pg_type it ON (ia.atttypid = it.oid AND it.typname in ('int2', 'int4', 'int8'))
WHERE c.relkind IN ('r', 'v', 'm', 'p', 'f')
AND t.typname IN ('geometry', 'geography')
AND has_table_privilege(c.oid, 'select')
AND postgis_typmod_srid(a.atttypmod) > 0
ORDER BY id 
INFO[0012] Query                                         args="[]" fields.time=8.721589ms pid=14005 rowCount=7 sql="SELECT\n\tFormat('%s.%s', n.nspname, c.relname) AS id,\n\tn.nspname AS schema,\n\tc.relname AS table,\n\tcoalesce(d.description, '') AS description,\n\ta.attname AS geometry_column,\n\tpostgis_typmod_srid(a.atttypmod) AS srid,\n\tpostgis_typmod_type(a.atttypmod) AS geometry_type,\n\tcoalesce(ia.attname, '') AS id_column,\n\t(\n\t\tSELECT array_agg(ARRAY[sa.attname, st.typname, coalesce(da.description,''), sa.attnum::text, sa.attnotnull]::text[] ORDER BY sa.attnum)\n\t\tFROM pg_attribute sa\n\t\tJOIN pg_type st ON sa.atttypid = st.oid\n\t\tLEFT JOIN pg_description da ON (c.oid = da.objoid and sa.attnum = da.objsubid)\n\t\tWHERE sa.attrelid = c.oid\n\t\tAND sa.attnum > 0\n\t\tAND NOT sa.attisdropped\n\t\tAND st.typname NOT IN ('geometry', 'geography')\n\t) AS props\nFROM pg_class c\nJOIN pg_namespace n ON (c.relnamespace = n.oid)\nJOIN pg_attribute a ON (a.attrelid = c.oid)\nJOIN pg_type t ON (a.atttypid = t.oid)\nLEFT JOIN pg_description d ON (c.oid = d.objoid AND d.objsubid = 0)\nLEFT JOIN pg_index i ON (c.oid = i.indrelid AND i.indisprimary\nAND i.indnatts = 1)\nLEFT JOIN pg_attribute ia ON (ia.attrelid = i.indexrelid)\nLEFT JOIN pg_type it ON (ia.atttypid = it.oid AND it.typname in ('int2', 'int4', 'int8'))\nWHERE c.relkind IN ('r', 'v', 'm', 'p', 'f')\nAND t.typname IN ('geometry', 'geography')\nAND has_table_privilege(c.oid, 'select')\nAND postgis_typmod_srid(a.atttypmod) > 0\nORDER BY id\n"
2023/02/13 14:51:46 http: panic serving 127.0.0.1:57678: runtime error: invalid memory address or nil pointer dereference
goroutine 23 [running]:
net/http.(*conn).serve.func1()
/usr/local/go/src/net/http/server.go:1850 +0xbf
panic({0xb7f780, 0x125de90})
/usr/local/go/src/runtime/panic.go:890 +0x262
net/http.(*timeoutHandler).ServeHTTP(0xc000391880, {0xd4eee8, 0xc0002e4000}, 0xc000208000)
/usr/local/go/src/net/http/server.go:3412 +0x7ea
net/http.serverHandler.ServeHTTP({0xd4cc00?}, {0xd4eee8, 0xc0002e4000}, 0xc000208000)
/usr/local/go/src/net/http/server.go:2947 +0x30c
net/http.(*conn).serve(0xc000138000, {0xd4f728, 0xc00019c690})
/usr/local/go/src/net/http/server.go:1991 +0x607
created by net/http.(*Server).Serve
/usr/local/go/src/net/http/server.go:3102 +0x4db
DEBU[0012] ---- Request cancelled by client after 9.191144ms