DapperLib / DapperLib/Dapper.Contrib
Dapper.Contrib Key caching issue
Nobody has claimed this yet.
- Dominant language
- C#
- Stars
- 293
- Forks
- 109
- PR merge metrics
- No merged PRs in 30d
Description
There is a bug in the caching logic of the KeyProperties. Method UpdateAsync() and DeleteAsync() alter the original cached list of properties key code ref.
So, if the first operation is a Update or Delete the "KeyPropertiesCache" return a pointer to the original list and the Update/Delete method add the explicitKeyProperties to the list. When the Insert() get called the "allPropertiesExceptKeyAndComputed" is wrong.
Test to reproduce it:
public async Task TestMethod()
{
var myClass = new MyClass()
{
AccountId = Guid.NewGuid(),
Name = "Some name"
};
using (IDbConnection db = new SqlConnection(connectionString))
{
//var x = await db.InsertAsync(myClass); // Add and test pass
var t = await db.UpdateAsync(myClass);
var r = await db.InsertAsync(myClass);
}
}
Suggested fix that all returns from cache-layer (KeyPropertiesCache, ExplicitKeyPropertiesCache, ComputedPropertiesCache etc.) should call .ToList() on the item before return it.
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
The relevant cache logic is in Dapper.Contrib/SqlMapperExtensions.Async.cs around line 217. Start with UpdateAsync, DeleteAsync, InsertAsync, and the KeyPropertiesCache behavior described in the issue, then reproduce the provided UpdateAsync-then-InsertAsync sequence. Done means cached property lists are not altered by update or delete operations and the regression case passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- csharp
- Domain
- databases
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100