fsprojects / SQLProvider

A general F# SQL database erasing type provider, supporting LINQ queries, schema exploration, individuals, CRUD operations and much more besides.
https://fsprojects.github.io/SQLProvider
Other
570 stars 144 forks source link

Error: "Unchanged entity encountered in update list - this should not be possible!" #647

Closed JordanMarr closed 4 years ago

JordanMarr commented 4 years ago

Description

I have a system that has been in production for a few weeks. It has been running fine until this morning where none of the users can save their work.

In the log I see this exception over and over: "System.Exception: Unchanged entity encountered in update list - this should not be possible!"

Any clues as to what this might mean?

Thorium commented 4 years ago

Which database?

Don't use the same context on multiple threads. Instead create a context per thread. (That is a limitation of database driver connection pooling rather than SQLProvider.)

Thorium commented 4 years ago

There is a lot of discussion about this in #238

JordanMarr commented 4 years ago

Thanks for the quick reply. It is using SQL Server.

Checking out that discussion now....

JordanMarr commented 4 years ago

I restarted the site after reading your comment, and it is saving now. So that buys me some time. Whew!

giuliohome commented 4 years ago

Hi! Can I ask you more details please? I'm getting the same issue from one of my users in Production. You closed without any intervention, but did you do anything else at code level then? In my case I don't think it is a concurrency problem.

JordanMarr commented 4 years ago

Hi! Can I ask you more details please? I'm getting the same issue from one of my users in Production. You closed without any intervention, but did you do anything else at code level then? In my case I don't think it is a concurrency problem.

It was not a bug, it was my own hasty configuration error: I had configured it in the asp.net core dependency injection subsystem as a singleton. A total rookie mistake.

Hope that helps!

giuliohome commented 4 years ago

@JordanMarr Thank you for your prompt reply! I will investigate as per your suggestion.

giuliohome commented 4 years ago

In my case it was one of the many possible errors from the db (a long user input causing a truncation on a column of a table in MS Sql Server), then my fix, shared here, consisted of (aside from the obvious alter table)

  1. wrapping the updates submit with a try

  2. clearing the updates of the context in case it throws

Honestly (YMMV) I would consider context.ClearUpdates() as the standard behaviour for exceptions, one should explicitly activate a flag to keep those "wrong" updates active after irrecoverable errors from db, IMO, but this is not the case for the current implementation of SQL Provider, hence my fix in my project.

Thorium commented 4 years ago

You might want to get the failed entities for other purposes (e.g. logging as described in my reply), that's why auto-clear is not a good option.

giuliohome commented 4 years ago

It is a good option, the current behaviour is very prone to errors.

Thorium commented 4 years ago

Maybe there could be some kind of override that would send the errors as events, and then the user should listen the events and to log any errors. But this is off-topic already, there is another thread open for that.