BUG #16268: SPI_getvalue requires IsTransactionState but TextDatumGetCString of SPI_getbinval - not!

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

BUG #16268: SPI_getvalue requires IsTransactionState but TextDatumGetCString of SPI_getbinval - not!

PG Bug reporting form
The following bug has been logged on the website:

Bug reference:      16268
Logged by:          RekGRpth
Email address:      [hidden email]
PostgreSQL version: 12.2
Operating system:   Docker alpine edge
Description:        

const char *data = SPI_getvalue(SPI_tuptable->vals[row],
SPI_tuptable->tupdesc, SPI_fnumber(SPI_tuptable->tupdesc, "data"));

raise TRAP: FailedAssertion("!(IsTransactionState())", File: "catcache.c",
Line: 1213)

but

const char *data = SPI_getvalue_my(SPI_tuptable->vals[row],
SPI_tuptable->tupdesc, SPI_fnumber(SPI_tuptable->tupdesc, "data"));

where

char *SPI_getvalue_my(HeapTuple tuple, TupleDesc tupdesc, int fnumber) {
    bool isnull;
    Datum datum = SPI_getbinval(tuple, tupdesc, fnumber, &isnull);
    if (isnull) return NULL;
    return TextDatumGetCString(datum);
}

works ok

Reply | Threaded
Open this post in threaded view
|

Re: BUG #16268: SPI_getvalue requires IsTransactionState but TextDatumGetCString of SPI_getbinval - not!

Michael Paquier-2
On Thu, Feb 20, 2020 at 05:06:24AM +0000, PG Bug reporting form wrote:
> const char *data = SPI_getvalue(SPI_tuptable->vals[row],
> SPI_tuptable->tupdesc, SPI_fnumber(SPI_tuptable->tupdesc, "data"));
>
> raise TRAP: FailedAssertion("!(IsTransactionState())", File: "catcache.c",
> Line: 1213)

Catalog cache lookups have to happen in the context of a transaction,
this is what this assertion failure means, so your code is doing
something incorrect.  We have such examples of short-term transactions
opened in the PostgreSQL code for some cache lookups.
IdentifySystem() in walsender.c looking for the database name is one
such example (see StartTransactionCommand and CommitTransactionCommand).
--
Michael

signature.asc (849 bytes) Download Attachment