Skip to content

Fix invalid handling of null DateTime parameters in Npgsql 6+ #3299

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

Merged
merged 1 commit into from
May 8, 2023

Conversation

hazzik
Copy link
Member

@hazzik hazzik commented May 4, 2023

Fixes #3291

@hazzik hazzik changed the base branch from master to 5.4.x May 4, 2023 10:53
@hazzik hazzik enabled auto-merge (squash) May 4, 2023 10:56
@hazzik hazzik added the t: Fix label May 4, 2023
@hazzik hazzik changed the title Fix support for null DateTime parameters for Npgsql 6+ Fix invalid handling of null DateTime parameters in Npgsql 6+ May 4, 2023
@hazzik hazzik merged commit ed7a6d8 into nhibernate:5.4.x May 8, 2023
@hazzik hazzik deleted the gh-3291-5.4.x branch May 8, 2023 09:54
@fredericDelaporte fredericDelaporte added this to the 5.4.3 milestone May 8, 2023
@fredericDelaporte
Copy link
Member

fredericDelaporte commented May 8, 2023

I have thought about checking where the regression had happened only after validating. It seems it was in 5.3.x. So we need a backport of the fix, now that it is merged into 5.4.

fredericDelaporte pushed a commit to fredericDelaporte/nhibernate-core that referenced this pull request May 8, 2023
Copy link
Member

@bahusoid bahusoid left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It seems it was in 5.3.x

Yes, original fix was added in 5.3.13. But it’s not a regression as DateTime handling was broken anyway with Npgsql6 (see #2994). So I would make it a low priority 5.3.x fix that can wait for other regression issues.

for (var i = 0; i < command.Parameters.Count; i++)
{
var parameter = command.Parameters[i];
if (parameter.Value is DateTime)
Copy link
Member

@bahusoid bahusoid May 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure I like this runtime type check for all parameters values.

It's not clear what original issue #2994 is about as no details are provided. But DateTime can represent multiple DbType types (Date, DateTime, Time). Original fix #3064 was applied only for DBType.DateTime.
So is it omission in original fix or other types are not affected and no fix is required? I wouldn't extend scope of fix unless it's really necessary.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's not clear what original issue #2994 is about as no details are provided.

There are breaking changes in Npgsql 6 that require a DateTime of certain Kind to match timestamp or timestamptz through a "help" of DbType.DateTime2 type. Here are some explanations: https://www.npgsql.org/doc/release-notes/6.0.html#detailed-notes and here: https://www.roji.org/postgresql-dotnet-timestamp-mapping

It is really hard to explain their motivation and the implementation. But it does not align with the type system used by NHibernate.

But DateTime can represent multiple DbType types (Date, DateTime, Time).

I don't think it applies here. However, I think, it is possible to write a more specific conversion.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, it does apply to DbType.Date. I'll adjust the fix.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Successfully merging this pull request may close these issues.

Npgsql 6+ issues with null DateTime parameter types
3 participants