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

EF Core + MySQL Empty JSON Stack Traces #376

Open
ncosentino opened this issue Nov 19, 2024 · 8 comments
Open

EF Core + MySQL Empty JSON Stack Traces #376

ncosentino opened this issue Nov 19, 2024 · 8 comments
Labels
area-sql bug Something isn't working

Comments

@ncosentino
Copy link

Disclaimer: This might have been because I migrated posts manually, but I am not entirely sure. They seem to render completely fine in the UI from what I can see, but I am getting application exceptions flooding Azure:

An exception occurred while iterating over the results of a query for context type 'LinkDotNet.Blog.Infrastructure.Persistence.Sql.BlogDbContext'. MySqlConnector.MySqlException (0x80004005): Invalid JSON text in argument 1 to function json_table: "The document is empty." at position 0. at MySqlConnector.Core.ServerSession.ReceiveReplyAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ServerSession.cs:line 894 at MySqlConnector.Core.ResultSet.ScanRowAsync(IOBehavior ioBehavior, Row row, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ResultSet.cs:line 244 at MySqlConnector.Core.ResultSet.ReadAsync(IOBehavior ioBehavior, CancellationToken cancellationToken) in /_/src/MySqlConnector/Core/ResultSet.cs:line 207 at MySqlConnector.MySqlDataReader.ReadAsync(CancellationToken cancellationToken) in /_/src/MySqlConnector/MySqlDataReader.cs:line 38 at Microsoft.EntityFrameworkCore.Query.Internal.SingleQueryingEnumerable 1.AsyncEnumerator.MoveNextAsync()

As you can see, it's spamming pretty good:
image

I am not exactly sure what to check here -- but I think tags might be the only thing that is JSON-esque in the database columns for a blog post? I could be wrong. I cannot access my MySQL instance from this machine, but I can try to query directly and see if I find any obvious records.

Posting this simply for visibility in case it pops up anywhere else for anyone. But I may be able to close it out if I find I made an invalid record manually.

@ncosentino
Copy link
Author

I have gone through all database records and ensured a ShortDescription is set and all Tags are set to at least have something like
["Programming"]

I'm still getting the error. For reference, I am trying to access this route:
https://devleader.ca/searchByTag/ROM
(This showed up in my cloudflare analytics so I was curious)

If I access something like this:
https://devleader.ca/searchByTag/programming

It all works as expected (no exception, and records load in the UI)

@linkdotnet
Copy link
Owner

Hey Nick,

I am pretty sure that has nothing to do with the approach of manually converting your blog posts. I suspect more MySQL or the MySQL driver for Entity Framework. I tested all the implementation details against MariaDB, which seems to have much better support for that (at least the more I dig into the topic). So I have to check what is the way forward (and don't use MariaDB for my tests :D)

PS: Also https://devleader.ca/searchByTag/programming will fail eventually if you wait.

@linkdotnet linkdotnet added bug Something isn't working area-sql labels Nov 20, 2024
@ncosentino
Copy link
Author

Another quick update: If I run everything locally from visual studio and I point at my prod database, all of the mentioned routes work without issue. Of course, if I use a tag that doesn't exist it just "works" by not showing content -- but there are no page issues or anything like that.

The only differences I can think of:

  • Hosting in Azure
  • Cloudflare

I can't see how either of these would cause the SQL query to get botched though.

@linkdotnet
Copy link
Owner

That makes the issue even more interesting. I try to find some time the upcoming days.

@linkdotnet
Copy link
Owner

There should be a new EF 9 Version of the Pomelo LINQ Driver. I hope that fixes things.

@linkdotnet
Copy link
Owner

image

I am battling a different kind of beast here :D

@linkdotnet
Copy link
Owner

I don't have a solution, nor do I have a clue what is the problem. But something about the term: Dev Leader Weekly throws of the JSON Support in MySQL. Using tags like "C#" or ".NET" do work fine, but as soon as I throw in Dev Leader Weekly into the mix,
a) I get the exception you are receiving
b) If I use the generated code from EF and just executed manually against the MySQL database, it retrieves post that don't even have the tag in them.

image

@linkdotnet
Copy link
Owner

Probably caused by: PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#1933

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-sql bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants