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

[release/6.0] Microsoft.Data.Sqlite: Fix handling of queries with RETURNING clause #31013

Merged
merged 1 commit into from
Jul 6, 2023

Conversation

bricelam
Copy link
Contributor

@bricelam bricelam commented May 31, 2023

Fixes #30851

When using the DELETE journaling mode in SQLite (Note, this is not the default for databases created by EF), the RETURNING clause on INSERT, UPDATE, and DELETE statements exhibits some unusual behavior. It will return results before the changes are actually persisted to the database. Only after consuming the entire DbDataReader (or disposing it) will it report that the table is busy and cannot be updated. This is the first statement we've encountered with this behavior.

This issue fixes a bug where errors encountered while disposing a DbDataReader were being swallowed/ignored by Microsoft.Data.Sqlite.

Customer impact

Two users have reported this issue. Because the error was previously ignored, it appeared to your application that the changes were successfully made to the database when, in fact, they were not. From the application's perspective, this results in changes made by statements with RETURNING clauses occasionally being lost (or not persisted).

The RETURNING clause was added to SQLite in the .NET 6 timeframe, and we started using it in certain cases in .NET 7.

Once users discover that this is an issue, they can work around it in various ways. For example, by using WAL journaling mode (the EF default, and the recommended one), by using shared cache mode, by wrapping the statement inside a transaction, or by using a separate SELECT statement instead of the RETURNING clause.

Regression

No. This bug has always existed but could only be hit by this unusual behavior of the RETURNING clause.

Risk

Low. This just surfaces errors that are already happening to the application via exceptions.

Verification

Automated tests added to verify a "busy" exception is always thrown.
Manually verified that the user-reported scenario using EF Core throws as well.

@bricelam bricelam requested a review from a team May 31, 2023 18:21
@ajcvickers ajcvickers modified the milestones: 7.0.9, 6.0.20 Jun 26, 2023
@wtgodbe wtgodbe merged commit 71fe707 into dotnet:release/6.0 Jul 6, 2023
@ajcvickers
Copy link
Contributor

@wtgodbe Should this be in 6.0.21?

@bricelam bricelam deleted the returning branch July 6, 2023 17:11
@wtgodbe wtgodbe modified the milestones: 6.0.20, 6.0.21 Jul 6, 2023
@wtgodbe
Copy link
Member

wtgodbe commented Jul 6, 2023

Should this be in 6.0.21?

Yes

@ajcvickers ajcvickers removed this from the 6.0.21 milestone Nov 14, 2023
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.

4 participants