GetSchema fails when enum is not in `public` · Issue #4392 · npgsql/npgsql · GitHub
Skip to content

GetSchema fails when enum is not in public #4392

Closed

Description

@JordanMarr

Steps to reproduce

I have noticed that creating a custom enum type and a table that references it in a custom schema (other than public) causes GetSchema to fail with an exception.

To reproduce:

Create a bug schema and run the following within it:

-- Create an enum in `experiment` schema
create type bug.colors AS ENUM ('red', 'yellow', 'blue');

-- Create a table in `experiment` schema that references the enum
create table person (
    name text not null,
    favorite_color bug.colors not null
);
    using conn = new Npgsql.NpgsqlConnection("...");
    conn.Open();
    // Next line will fail with "42704: type "colors" does not exist"
    var columns = conn.GetSchema("Columns");

Workaround:
I can workaround the issue by also creating the enum definition in the public schema.

The issue

I think that maybe GetSchema("Columns") is making the assumption that all enums must live in public.

If you are seeing an exception, include the full exceptions details (message and stack trace).

Exception message:

42704: type "colors" does not exist

Stack trace:

   at Npgsql.NpgsqlConnector.<<ReadMessage>g__ReadMessageLong|194_0>d.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Threading.Tasks.ValueTask`1.get_Result()
   at System.Runtime.CompilerServices.ValueTaskAwaiter`1.GetResult()
   at Npgsql.NpgsqlDataReader.<Read>d__40.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Npgsql.NpgsqlDataReader.Read()
   at Npgsql.NpgsqlDataAdapter.<Fill>d__27.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Npgsql.NpgsqlDataAdapter.<Fill>d__26.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at Npgsql.NpgsqlDataAdapter.<Fill>d__26.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Npgsql.NpgsqlSchema.<GetColumns>d__9.MoveNext()
   at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
   at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
   at System.Runtime.CompilerServices.TaskAwaiter`1.GetResult()
   at Npgsql.NpgsqlConnection.GetSchema(String collectionName, String[] restrictions)
   at Npgsql.NpgsqlConnection.GetSchema(String collectionName)
   at SqlHydra.Npgsql.NpgsqlSchemaProvider.getSchema(Config cfg) in C:\_github\SqlHydra\src\SqlHydra.Npgsql\NpgsqlSchemaProvider.fs:line 14
   at Npgsql.Generation.lazySchema@29-2.Invoke(Unit unitVar) in C:\_github\SqlHydra\src\Tests\Npgsql\Generation.fs:line 29
   at System.Lazy`1.ViaFactory(LazyThreadSafetyMode mode)

Further technical details

Npgsql version: Reproduced in v5.0.7 and v6.0.3

PostgreSQL version:

SELECT version();
PostgreSQL 14.2 (Debian 14.2-1.pgdg110+1) on x86_64-pc-linux-gnu, compiled by gcc (Debian 10.2.1-6) 10.2.1 20210110, 64-bit

Operating system:
Windows 10

Other details about my project setup:

Activity

  1. self-assigned this
    on Mar 30, 2022
  2. added this to the 6.0.4 milestone on Mar 30, 2022
  3. added a commit that references this issue on Mar 30, 2022
    ca03420
  4. added 2 commits that reference this issue on Mar 30, 2022
    a020c78
    a6e3e45
  5. mukutdanielroy commented on Jan 15, 2025

    @mukutdanielroy

    did it worked rather than public schema?

  6. added theissue type on Jun 18, 2025
  7. added a commit that references this issue on Apr 4, 2026
    9dbedbe
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

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions