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

npgsql 8 regression: System.ArgumentException: Name is too long and would be truncated #5460

Closed
cjlotz opened this issue Nov 27, 2023 · 0 comments · Fixed by #5463
Closed
Assignees
Labels
Milestone

Comments

@cjlotz
Copy link

cjlotz commented Nov 27, 2023

Steps to reproduce

  • Upgrade to Npgsql 8.0
  • Code starts failing with System.ArgumentException: Name is too long and would be truncated to: ... exceptions

The issue

The length calculation in the DataTypeName ctor is incorrect.

System.ArgumentException: Name is too long and would be truncated to: ampc.asset_monitoring_point_trigger_expression_parameter_cache_ite
   at Npgsql.Internal.Postgres.DataTypeName..ctor(String fullyQualifiedDataTypeName, Boolean validated)
   at Npgsql.Internal.Postgres.DataTypeName..ctor(String fullyQualifiedDataTypeName)
   at Npgsql.Internal.Postgres.DataTypeName.FromDisplayName(String displayName, String schema)
   at Npgsql.PostgresTypes.PostgresType..ctor(String ns, String name, UInt32 oid)
   at Npgsql.PostgresTypes.PostgresCompositeType..ctor(String ns, String name, UInt32 oid)
   at Npgsql.PostgresDatabaseInfo.LoadBackendTypes(NpgsqlConnector conn, NpgsqlTimeout timeout, Boolean async)
   at Npgsql.PostgresDatabaseInfo.LoadPostgresInfo(NpgsqlConnector conn, NpgsqlTimeout timeout, Boolean async)
   at Npgsql.PostgresDatabaseInfoFactory.Load(NpgsqlConnector conn, NpgsqlTimeout timeout, Boolean async)
   at Npgsql.Internal.NpgsqlDatabaseInfo.Load(NpgsqlConnector conn, NpgsqlTimeout timeout, Boolean async)
   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.UnpooledDataSource.Get(NpgsqlConnection conn, NpgsqlTimeout timeout, Boolean async, CancellationToken cancellationToken)
   at Npgsql.NpgsqlConnection.<Open>g__OpenAsync|42_0(Boolean async, CancellationToken cancellationToken)
   at Pragma.OnKey.Data.SqlConnection.Open() in C:\Dev\git\onkey-plus-server\src\Pragma.OnKey.Infrastructure\Data\SqlConnection.cs:line 205
   at Pragma.OnKey.Migrations.MigrationContext.InitialiseMigration(IMigrationDao dao, IMigrationRegistry migrationRegistry) in C:\Dev\git\onkey-plus-server\src\Pragma.OnKey.Infrastructure\Migrations\MigrationContext.cs:line 536
   at Pragma.OnKey.Migrations.MigrationContext.InitialiseMigration(IMigrationDao dao, IMigrationRegistry migrationRegistry) in C:\Dev\git\onkey-plus-server\src\Pragma.OnKey.Infrastructure\Migrations\MigrationContext.cs:line 545
   at Pragma.OnKey.Migrations.MigrationContext.RunMigration(IMigrationDao dao, IMigrationRegistry migrationRegistry, CancellationToken cancellationToken) in C:\Dev\git\onkey-plus-server\src\Pragma.OnKey.Infrastructure\Migrations\Migrati

From investigation it seems the length is currently calculated incorrectly in the ctor here

Shouldn't it rather be be var typeNameLength = fullyQualifiedDataTypeName.Length - (schemaEndIndex + 1);

Can be verified with the following snippet:

	// create 63 characters max PG length type
	var name = "asset_monitoring_point_trigger_expression_parameter_cache_item";
	var fullyQualifiedDataTypeName= $"ampc.{name}";
	var schemaEndIndex = fullyQualifiedDataTypeName.IndexOf('.');

	var buggyTypeNameLength = fullyQualifiedDataTypeName.Length - schemaEndIndex + 1;
	var fixedTypeNameLength = fullyQualifiedDataTypeName.Length - (schemaEndIndex + 1);
	var actualLength = name.Length;
	
	Debug.Assert(actualLength == fixedTypeNameLength, "Bug not fixed");		
	Debug.Assert(actualLength == buggyTypeNameLength, "Bug illustrated");	

Further technical details

Npgsql version: 8.0.0
PostgreSQL version:
Operating system: Windows

@cjlotz cjlotz changed the title Npsql 8 regression: System.ArgumentException: Name is too long and would be truncated npgsql 8 regression: System.ArgumentException: Name is too long and would be truncated Nov 27, 2023
NinoFloris added a commit that referenced this issue Nov 27, 2023
@NinoFloris NinoFloris added the bug label Nov 27, 2023
@NinoFloris NinoFloris self-assigned this Nov 27, 2023
@NinoFloris NinoFloris added this to the 8.0.1 milestone Nov 27, 2023
NinoFloris added a commit that referenced this issue Nov 28, 2023
NinoFloris added a commit that referenced this issue Nov 28, 2023
Fixes #5460

(cherry picked from commit 5ba1592)
JonasWestman pushed a commit to monitor-erp/npgsql that referenced this issue Dec 20, 2023
Fixes npgsql#5460

(cherry picked from commit 5ba1592)
Signed-off-by: monjowe <jonas.westman@monitor.se>
JonasWestman pushed a commit to monitor-erp/npgsql that referenced this issue Dec 21, 2023
Fixes npgsql#5460

(cherry picked from commit 5ba1592)
Signed-off-by: monjowe <jonas.westman@monitor.se>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants