Skip to content

Can't load enums on PostgreSQL 9.0 or older #2023

Closed

Description

@evandrofuhr

Steps to reproduce

Open connection at PostgreSQL 9.0 version.

The issue

When I open a connection in the PostgreSQL 9.0 version, Npgsql loads the enumeration information since version 8.3, but in the PostgresSQL 9.0 version the column 'enumsortorder' does not yet exist, as it is only available in the next version (9.1).

Exception message: 42703: column"enumsortorder" does not exists
Stack trace: 
`   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext()
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Npgsql.NpgsqlConnector.<>c__DisplayClass161_0.<<ReadMessage>g__ReadMessageLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 1032
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDataReader.<NextResult>d__46.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 444
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDataReader.NextResult() in C:\projects\npgsql\src\Npgsql\NpgsqlDataReader.cs:line 340
   at Npgsql.PostgresDatabaseInfo.<LoadBackendTypes>d__11.MoveNext() in C:\projects\npgsql\src\Npgsql\PostgresDatabaseInfo.cs:line 253
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.PostgresDatabaseInfo.<LoadPostgresInfo>d__3.MoveNext() in C:\projects\npgsql\src\Npgsql\PostgresDatabaseInfo.cs:line 72
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.PostgresDatabaseInfoFactory.<Load>d__0.MoveNext() in C:\projects\npgsql\src\Npgsql\PostgresDatabaseInfo.cs:line 43
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlDatabaseInfo.<Load>d__79.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlDatabaseInfo.cs:line 250
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnector.<LoadDatabaseInfo>d__150.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 466
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnector.<Open>d__149.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnector.cs:line 455
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.ConnectorPool.<AllocateLong>d__19.MoveNext() in C:\projects\npgsql\src\Npgsql\ConnectorPool.cs:line 298
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnection.<>c__DisplayClass32_0.<<Open>g__OpenLong|0>d.MoveNext() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 318
--- End of stack trace from previous location where exception was thrown ---
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at Npgsql.NpgsqlConnection.Open() in C:\projects\npgsql\src\Npgsql\NpgsqlConnection.cs:line 153
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.OpenDbConnection(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Storage.RelationalConnection.Open(Boolean errorsExpected)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.BufferlessMoveNext(DbContext _, Boolean buffer)
   at Npgsql.EntityFrameworkCore.PostgreSQL.Storage.Internal.NpgsqlExecutionStrategy.Execute[TState,TResult](TState state, Func`3 operation, Func`3 verifySucceeded) in C:\projects\EFCore.PG\src\EFCore.PG\Storage\Internal\NpgsqlExecutionStrategy.cs:line 60
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryingEnumerable`1.Enumerator.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.<_TrackEntities>d__17`2.MoveNext()
   at Microsoft.EntityFrameworkCore.Query.Internal.LinqOperatorProvider.ExceptionInterceptor`1.EnumeratorExceptionInterceptor.MoveNext()
   at System.Collections.Generic.List`1.AddEnumerable(IEnumerable`1 enumerable)
   at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
   at MicroSalesPainel.Negocio.ProgTerceirizadoNegocio.<GerarDados>d__4.MoveNext() in C:\Projeto\Painel\MicroSalesPainel.Negocio\ProgTerceirizadoNegocio.cs:line 65`

Further technical details

Npgsql version: 4.1.0
PostgreSQL version: 9.0.23
Operating system: Windows 10 x64

Other details about my project setup:

Activity

  1. austindrenski commented on Jun 28, 2018

    @austindrenski
    Contributor

    Similar to this, 9.0.23 reached its end-of-life in September 2015.

    Were you previously using a version of Npgsql that doesn't break this?

  2. evandrofuhr commented on Jun 28, 2018

    @evandrofuhr
    Author

    @austindrenski No, my application was raised recently to access a legacy database. I did test in previous versions of Ngpgsql but it inputs a lot of others bugs.

  3. austindrenski commented on Jun 28, 2018

    @austindrenski
    Contributor

    It does seem like {Npgsql,Posgres}DatabaseInfo is set up to support this type of compatibility. except for the enumsortorder column.

    cc: @roji @Brar

    /// <summary>
    /// Whether the backend supports enum types.
    /// </summary>
    public virtual bool SupportsEnumTypes => Version >= new Version(8, 3, 0);

    /*** Load field definitions for (free-standing) composite types ***/
    SELECT typ.oid, att.attname, att.atttypid
    FROM pg_type AS typ
    JOIN pg_namespace AS ns ON (ns.oid = typ.typnamespace)
    JOIN pg_class AS cls ON (cls.oid = typ.typrelid)
    JOIN pg_attribute AS att ON (att.attrelid = typ.typrelid)
    WHERE
    (typ.typtype = 'c' AND {(loadTableComposites ? "ns.nspname NOT IN ('pg_catalog', 'information_schema', 'pg_toast')" : "cls.relkind='c'")}) AND
    attnum > 0 AND /* Don't load system attributes */
    NOT attisdropped
    ORDER BY typ.typname, att.attnum;
    {(withEnum ? @"
    /*** Load enum fields ***/
    SELECT pg_type.oid, enumlabel
    FROM pg_enum
    JOIN pg_type ON pg_type.oid=enumtypid
    ORDER BY oid, enumsortorder;" : "")}
    ";

  4. roji commented on Jun 29, 2018

    @roji
    Member

    If I'm not mistaken we didn't load the enumsortorder attribute before 4.0. It should be pretty trivial to not sort by that column on pre-9.1 databases, so why not do it even if they're no longer officially supported...

    @Brar or @austindrenski, do you feel like adding this?

  5. added this to the 4.0.1 milestone on Jun 29, 2018
  6. changed the title [-]Error on load Enum fields[/-] [+]Can't load enums on PostgreSQL 9.0 or older[/+] on Jun 29, 2018
  7. austindrenski commented on Jun 29, 2018

    @austindrenski
    Contributor

    Sure, I'll look into a patch soon.

  8. roji commented on Jun 30, 2018

    @roji
    Member

    Merged and backported to 4.0.1, thanks @austindrenski!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions