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

Problem with Npgsql 8: A PostgreSQL type with the name 'unknown' was not found in the current database info #15281

Closed
amotl opened this issue Jan 4, 2024 · 2 comments · Fixed by #15291
Assignees
Labels
triage An issue that needs to be triaged by a maintainer

Comments

@amotl
Copy link
Member

amotl commented Jan 4, 2024

CrateDB version

5.5.1

CrateDB setup information

Standard, e.g. Docker.

Problem description

When connecting to CrateDB using Npgsql 8.0.0, which has been released in November 2023, it fails like outlined at crate/crate-qa#289 and below, with the error message A PostgreSQL type with the name 'unknown' was not found in the current database info. The problem has also been reported on the community forum, and there is also an upstream conversation about this topic.

Steps to Reproduce

I can't provide a dedicated repro yet, but the corresponding code in crate-qa already triggers the problem, see crate/crate-qa#289.

Actual Result

Unhandled exception. System.ArgumentException: A PostgreSQL type with the name 'unknown' was not found in the current database info
   at Npgsql.Internal.NpgsqlDatabaseInfo.GetPostgresType(String pgName)
   at Npgsql.Internal.PgSerializerOptions..ctor(NpgsqlDatabaseInfo databaseInfo, Func`1 timeZoneProvider)
   at Npgsql.NpgsqlDataSource.Bootstrap(NpgsqlConnector connector, NpgsqlTimeout timeout, Boolean forceReload, Boolean async, CancellationToken cancellationToken)
   at Npgsql.Internal.NpgsqlConnector.Open(NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.PoolingDataSource.OpenNewConnector(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.PoolingDataSource.<Get>g__RentAsync|34_0(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.Open()
   at stock_npgsql.Program.Main(String[] args) in /var/lib/jenkins/workspace/CrateDB/qa/crate_qa_on_pr@2/tests/client_tests/stock_npgsql/Program.cs:line 81
   at stock_npgsql.Program.<Main>(String[] args)
Failure running: /var/lib/jenkins/workspace/CrateDB/qa/crate_qa_on_pr@2/tests/client_tests/stock_npgsql/bin/Debug/net8.0/stock_npgsql 127.0.0.1 5432
script returned exit code 1

Expected Result

Connecting to CrateDB works, even with Npgsql 8.x.x.

Possible Solutions

@roji, the author of Npgsql, recommends at npgsql/npgsql#5503 (comment):

[...] the unknown type is a standard type in PostgreSQL, and therefore Npgsql depends on it. I'd recommend getting in touch with CrateDB to see what can be done on their side.

@amotl amotl added the triage An issue that needs to be triaged by a maintainer label Jan 4, 2024
@amotl amotl changed the title A PostgreSQL type with the name 'unknown' was not found in the current database info Problem with Npgsql 8: A PostgreSQL type with the name 'unknown' was not found in the current database info Jan 4, 2024
@roji
Copy link

roji commented Jan 4, 2024

/cc @NinoFloris

@amotl
Copy link
Member Author

amotl commented Jan 6, 2024

@roji: Thank you for tagging @NinoFloris. Nino, I just discovered you made an attempt with npgsql/npgsql@a5aa54b3d to fix this on behalf of Npgsql, thank you very much for your efforts.

I guess it will be a good idea to take the chance to improve PostgreSQL compatibility on CrateDB, but, at the same time, we can't travel back in time to improve previous releases, so your compatibility fix could be suitable for people aiming to use Npgsql 8 to connect to previous versions of CrateDB.

@mfussenegger mfussenegger self-assigned this Jan 8, 2024
mfussenegger added a commit that referenced this issue Jan 8, 2024
Closes #15281

Looks like in PostgreSQL it is handled as cstring:
From `varlena.c`:

    /*
     *		unknownin			- converts cstring to internal representation
     */
    Datum
    unknownin(PG_FUNCTION_ARGS)
    {
    	char	   *str = PG_GETARG_CSTRING(0);

    	/* representation is same as cstring */
    	PG_RETURN_CSTRING(pstrdup(str));
    }

    /*
     *		unknownout			- converts internal representation to cstring
     */
    Datum
    unknownout(PG_FUNCTION_ARGS)
    {
    	/* representation is same as cstring */
    	char	   *str = PG_GETARG_CSTRING(0);

    	PG_RETURN_CSTRING(pstrdup(str));
    }

    /*
     *		unknownrecv			- converts external binary format to unknown
     */
    Datum
    unknownrecv(PG_FUNCTION_ARGS)
    {
    	StringInfo	buf = (StringInfo) PG_GETARG_POINTER(0);
    	char	   *str;
    	int			nbytes;

    	str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
    	/* representation is same as cstring */
    	PG_RETURN_CSTRING(str);
    }

    /*
     *		unknownsend			- converts unknown to binary format
     */
    Datum
    unknownsend(PG_FUNCTION_ARGS)
    {
    	/* representation is same as cstring */
    	char	   *str = PG_GETARG_CSTRING(0);
    	StringInfoData buf;

    	pq_begintypsend(&buf);
    	pq_sendtext(&buf, str, strlen(str));
    	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
    }
mfussenegger added a commit that referenced this issue Jan 8, 2024
Closes #15281

Looks like in PostgreSQL it is handled as cstring:
From `varlena.c`:

    /*
     *		unknownin			- converts cstring to internal representation
     */
    Datum
    unknownin(PG_FUNCTION_ARGS)
    {
    	char	   *str = PG_GETARG_CSTRING(0);

    	/* representation is same as cstring */
    	PG_RETURN_CSTRING(pstrdup(str));
    }

    /*
     *		unknownout			- converts internal representation to cstring
     */
    Datum
    unknownout(PG_FUNCTION_ARGS)
    {
    	/* representation is same as cstring */
    	char	   *str = PG_GETARG_CSTRING(0);

    	PG_RETURN_CSTRING(pstrdup(str));
    }

    /*
     *		unknownrecv			- converts external binary format to unknown
     */
    Datum
    unknownrecv(PG_FUNCTION_ARGS)
    {
    	StringInfo	buf = (StringInfo) PG_GETARG_POINTER(0);
    	char	   *str;
    	int			nbytes;

    	str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
    	/* representation is same as cstring */
    	PG_RETURN_CSTRING(str);
    }

    /*
     *		unknownsend			- converts unknown to binary format
     */
    Datum
    unknownsend(PG_FUNCTION_ARGS)
    {
    	/* representation is same as cstring */
    	char	   *str = PG_GETARG_CSTRING(0);
    	StringInfoData buf;

    	pq_begintypsend(&buf);
    	pq_sendtext(&buf, str, strlen(str));
    	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
    }
@mergify mergify bot closed this as completed in #15291 Jan 8, 2024
mergify bot pushed a commit that referenced this issue Jan 8, 2024
Closes #15281

Looks like in PostgreSQL it is handled as cstring:
From `varlena.c`:

    /*
     *		unknownin			- converts cstring to internal representation
     */
    Datum
    unknownin(PG_FUNCTION_ARGS)
    {
    	char	   *str = PG_GETARG_CSTRING(0);

    	/* representation is same as cstring */
    	PG_RETURN_CSTRING(pstrdup(str));
    }

    /*
     *		unknownout			- converts internal representation to cstring
     */
    Datum
    unknownout(PG_FUNCTION_ARGS)
    {
    	/* representation is same as cstring */
    	char	   *str = PG_GETARG_CSTRING(0);

    	PG_RETURN_CSTRING(pstrdup(str));
    }

    /*
     *		unknownrecv			- converts external binary format to unknown
     */
    Datum
    unknownrecv(PG_FUNCTION_ARGS)
    {
    	StringInfo	buf = (StringInfo) PG_GETARG_POINTER(0);
    	char	   *str;
    	int			nbytes;

    	str = pq_getmsgtext(buf, buf->len - buf->cursor, &nbytes);
    	/* representation is same as cstring */
    	PG_RETURN_CSTRING(str);
    }

    /*
     *		unknownsend			- converts unknown to binary format
     */
    Datum
    unknownsend(PG_FUNCTION_ARGS)
    {
    	/* representation is same as cstring */
    	char	   *str = PG_GETARG_CSTRING(0);
    	StringInfoData buf;

    	pq_begintypsend(&buf);
    	pq_sendtext(&buf, str, strlen(str));
    	PG_RETURN_BYTEA_P(pq_endtypsend(&buf));
    }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
triage An issue that needs to be triaged by a maintainer
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants