-
-
Notifications
You must be signed in to change notification settings - Fork 403
Description
Steps to reproduce
Run the custom project to see it crashing
PomeloBugJsonExtract.zip
The issue
In some places, in the code, JSON_EXTRACT is used for getting value of a JSON field when using projection or any other mean of directly getting data. But when the data is null, JSON_EXTRACT does return the string value "null" instead of the mysql null value, as intended in the spec : https://bugs.mysql.com/bug.php?id=85755
Sadly if you have a Nullable<Datetime> later in ef core when trying to convert it will use the string representation instead of the correct null value and crash with
---> System.FormatException: Couldn't interpret value as a valid DateTime: null
at MySqlConnector.Core.Row.GetDateTime(Int32 ordinal) in /_/src/MySqlConnector/Core/Row.cs:line 336
at MySqlConnector.MySqlDataReader.GetDateTime(Int32 ordinal) in /_/src/MySqlConnector/MySqlDataReader.cs:line 264
at lambda_method186(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator)
--- End of inner exception stack trace ---
at lambda_method186(Closure, QueryContext, DbDataReader, ResultContext, SingleQueryResultCoordinator)
at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable`1.Enumerator.MoveNext()
be aware that the null indication here is not a real null value but instead a string "null" in
The naive solution
If we replace all call with JSON_VALUE we get a correct null value instead of a string and "everything" seems to work correctly
Further technical details
MySQL version: 8.3.0-1.el8
Operating system: Window11
Pomelo.EntityFrameworkCore.MySql version: 8.0.2