Bug #89982 Insert statements are truncating JSON columns to 65k when using EF Core 2.0
Submitted: 9 Mar 2018 11:44 Modified: 30 Mar 2018 10:22
Reporter: Clodoaldo cltschoke Email Updates:
Status: Can't repeat Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:MySql.Data.EntityFrameworkCore (6.10.5) OS:Ubuntu (16.04.3 LTS (GNU/Linux 4.4.0-1049))
Assigned to: CPU Architecture:Any
Tags: EF Core, json

[9 Mar 2018 11:44] Clodoaldo cltschoke
Description:
Getting this error on inserting data into mysql table containing json column:

MySql.Data.MySqlClient.MySqlException (0x80004005): Invalid JSON text: "Missing a closing quotation mark in string." at position 65534 in value for column 'PropertyEvents.ContentObject'.

Based on the following log message, it appears that the INSERT statement generated by EF is limiting the parameter size to 65K, but couldn´t understand why:

"Microsoft.EntityFrameworkCore.Database.Command:Error: Failed executing DbCommand (989ms) [Parameters=[@p0='?' (Size = 65535)], CommandType='Text', CommandTimeout='30']
INSERT INTO PropertyEvents (ContentObject) VALUES (@p0);
SELECT Id FROM PropertyEvents WHERE ROW_COUNT() = 1 AND Id=LAST_INSERT_ID();

This is the complete exception message:

MySql.Data.MySqlClient.MySqlException (0x80004005): Invalid JSON text: "Missing a closing quotation mark in string." at position 65534 in value for column 'PropertyEvents.ContentObject'.
at MySql.Data.MySqlClient.MySqlStream.ReadPacket()
at MySql.Data.MySqlClient.NativeDriver.GetResult(Int32& affectedRow, Int64& insertedId)
at MySql.Data.MySqlClient.Driver.NextResult(Int32 statementId, Boolean force)
at MySql.Data.MySqlClient.MySqlDataReader.NextResult()
at MySql.Data.MySqlClient.MySqlCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.Common.DbCommand.ExecuteDbDataReaderAsync(CommandBehavior behavior, CancellationToken cancellationToken)
--- End of stack trace from previous location where exception was thrown ---
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)
at Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommand.d__17.MoveNext()

How to repeat:
Configure EF Core Code First with the following entity type:
public class PropertyEvent
{
private PropertyEvent()
{
}

    public int Id { get; private set; }
    public string ContentObject { get; private set; }
}
using this configuration:
sealed class PropertyEventMap : IEntityTypeConfiguration
{
public void Configure(EntityTypeBuilder builder)
{
builder.Property(p => p.ContentObject).IsRequired().HasColumnType("JSON");
}
}

and then converts a json object greater than 65 k into PropertyEvent.ContentObject property and tries to insert it into db using "context.SaveChangesAsync()"

Further technical details
EF Core version: EF Core (2.01)
Database Provider: MySql.Data.EntityFrameworkCore (6.10.5) / MySQL 5.7.17
Operating system: Win10 Pro 64 bits (version 1709 build 16299.248)
IDE: Visual Studio 2017 (15.4.2)
[13 Mar 2018 8:04] Chiranjeevi Battula
Hello Clodoaldo,

Thank you for the bug report.
Could you please provide repeatable steps (exact steps/sample project, MySQl version,insert statements full stack trace etc. - please make it as private if you prefer) to confirm this issue at our end?

Thanks,
Chiranjeevi.
[14 Mar 2018 19:51] Clodoaldo cltschoke
sample project with database creation and endpoint to reproduce the error

Attachment: WebApplication1.rar (application/octet-stream, text), 5.75 KiB.

[14 Mar 2018 19:55] Clodoaldo cltschoke
Hi,

Attached a project sample. To reproduce this error run the project and call "http://localhost:61860/api/values" using POST, than pass a string greater than 65k in the body. 

In my case, I´m converting a image file to base64string.

Using this components/versions:

Visual Studio 2017 (15.4.2)
EF Core 2.01
MySQL 5.7.17
MySql.Data.EntityFrameworkCore (6.10.5)
Win10 Pro 64 bits (version 1709 build 16299.248)

tks.
[30 Mar 2018 10:22] Chiranjeevi Battula
Hello Clodoaldo,

Thank you for the feedback.
I could not repeat the issue at our end using with Visual Studio 2017,MySQL 5.7.21, Connector/NET 6.10.5 version.
If you can provide more information, feel free to add it to this bug and change the status back to 'Open'.

Thank you for your interest in MySQL.

Thanks,
Chiranjeevi.
[30 Mar 2018 10:24] Chiranjeevi Battula
Log

Attachment: 89982.txt (text/plain), 51.63 KiB.