Opened 4 years ago

Closed 4 years ago

#4695 closed defect (fixed)

ERROR: GetGenericCacheCollection: Could not find upper context ST_AsGeoJSON and pg13

Reported by: robe Owned by: pramsey
Priority: blocker Milestone: PostGIS 3.1.0
Component: postgis Version: master
Keywords: Cc:

Description (last modified by robe)

I'm running this query on PostGIS 3.1.0dev

POSTGIS="3.1.0dev 3.1.0alpha1-122-g16121bf79" [EXTENSION] PGSQL="130" GEOS="3.9.0-CAPI-1.14.0" PROJ="6.2.1" LIBXML="2.9.9" LIBJSON="0.12" LIBPROTOBUF="1.2.1" WAGYU="0.5.0 (Internal)"

and on PostgreSQL 13beta1 (headish).

Steps to replicate the issue:

 CREATE TABLE test AS 
 SELECT row_number()OVER() AS id, 'test' || i::text || j::text AS name, ST_SetSRID(ST_Point(i,j),2227) AS geom
 FROM generate_series(1,10) AS i, generate_series(5,10,2) AS j;


SELECT ST_ASGeoJSON(c)
FROM test AS c;
 

Yields error:

ERROR:  GetGenericCacheCollection: Could not find upper context
SQL state: XX000

This same query seems to work fine on PostgreSQL 12 with PostGIS 3.1.0. I haven't tested with PostGIS 3.0 and 13 yet but assume it has the same issue.

I'm guessing it has to do with the interaction of spatial_ref_sys, since this works fine:

 CREATE TABLE test2 AS 
 SELECT row_number()OVER() AS id, 'test' || i::text || j::text AS name, ST_Point(i,j) AS geom
 FROM generate_series(1,10) AS i, generate_series(5,10,2) AS j;
 
SELECT ST_ASGeoJSON(c)
FROM test2 AS c;

Change History (7)

comment:1 by robe, 4 years ago

Description: modified (diff)

comment:2 by robe, 4 years ago

FWIW might be related to #4674 maybe similar thing going on here.

comment:3 by Algunenano, 4 years ago

I'm not seeing the ST_AsGeoJSON call and I'm confused this works in PG12 but not in 13. If I had to guess I'd say the issue could be in https://github.com/postgis/postgis/blob/b48fb3e2272568aa6310fc26aefc69010d4f37e3/postgis/lwgeom_out_geojson.c#L170

I'll try to reproduce it and get more tests around it

comment:4 by robe, 4 years ago

Description: modified (diff)

Sorry about that — I completely forgot to include the actual code :) so focused on creating test data.

comment:5 by robe, 4 years ago

@Alguenano

You think it might be related to there removal of stuff in 13 around heap/table

Like what had to be fixed here

https://github.com/pramsey/pgsql-ogr-fdw/commit/6b0f4690e49ef4e0203252b2a87d25a173afc1ad

Though I would think it wouldn't compile at all

comment:6 by Algunenano, 4 years ago

You think it might be related to there removal of stuff in 13 around heap/table

No, it's related to the cache I added to ST_AsGeoJSON to limit the amount of accesses to spatial_ref_sys (ideally to do it just once per relation).

The problem comes from the fact that we cache our stuff in the parent memory context, but when we use DirectFunctionCall we are calling it without declaring a parent, so it fails when trying to use the cache.

I can reproduce it in PG12 with latest Postgis, so it should be an easy fix.

comment:7 by Algunenano, 4 years ago

Resolution: fixed
Status: newclosed

Should be fixed by https://trac.osgeo.org/postgis/changeset/7feaa9d82c37efb5d5454e0ac144878062487bde/git. I make a mistake with the ticket number in the commit message.

Note: See TracTickets for help on using tickets.