From 4fed269d9617136805e77e2799f904a24d6e6a7e Mon Sep 17 00:00:00 2001 From: Alex Zaytsev Date: Sun, 4 Feb 2024 19:38:30 +1000 Subject: [PATCH 1/2] Backport fix null reference in tests with Npgsql 8 --- .../PostgresExceptionConverterExample.cs | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/NHibernate.Test/ExceptionsTest/PostgresExceptionConverterExample.cs b/src/NHibernate.Test/ExceptionsTest/PostgresExceptionConverterExample.cs index e4142c32f7f..ee794f0b9de 100644 --- a/src/NHibernate.Test/ExceptionsTest/PostgresExceptionConverterExample.cs +++ b/src/NHibernate.Test/ExceptionsTest/PostgresExceptionConverterExample.cs @@ -1,6 +1,6 @@ using System; -using System.Data.Common; using NHibernate.Exceptions; +using Npgsql; namespace NHibernate.Test.ExceptionsTest { @@ -10,23 +10,23 @@ public class PostgresExceptionConverterExample : ISQLExceptionConverter public Exception Convert(AdoExceptionContextInfo exInfo) { - var sqle = ADOExceptionHelper.ExtractDbException(exInfo.SqlException) as DbException; - if (sqle != null) + if (ADOExceptionHelper.ExtractDbException(exInfo.SqlException) is PostgresException pge) { - string code = (string)sqle.GetType().GetProperty("Code").GetValue(sqle, null); - + string code = pge.SqlState; if (code == "23503") { - return new ConstraintViolationException(exInfo.Message, sqle.InnerException, exInfo.Sql, null); + return new ConstraintViolationException(exInfo.Message, pge.InnerException, exInfo.Sql, null); } + if (code == "42P01") { - return new SQLGrammarException(exInfo.Message, sqle.InnerException, exInfo.Sql); + return new SQLGrammarException(exInfo.Message, pge.InnerException, exInfo.Sql); } } + return SQLStateConverter.HandledNonSpecificException(exInfo.SqlException, exInfo.Message, exInfo.Sql); } #endregion } -} \ No newline at end of file +} From a40b170331f37769c72a30a01798c6e07958372f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20Delaporte?= <12201973+fredericdelaporte@users.noreply.github.com> Date: Sun, 12 May 2024 12:52:30 +0200 Subject: [PATCH 2/2] Upgrade Npgsql to an non-vulnerable version --- src/NHibernate.Test/NHibernate.Test.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/NHibernate.Test/NHibernate.Test.csproj b/src/NHibernate.Test/NHibernate.Test.csproj index e5e553f5b30..3b2b0dab83b 100644 --- a/src/NHibernate.Test/NHibernate.Test.csproj +++ b/src/NHibernate.Test/NHibernate.Test.csproj @@ -66,7 +66,7 @@ - +