Hi,
We're encountering concurrency errors when making parallel requests, even when the entity remains unmodified. Upon investigation, we found that the last modification time and concurrency stamp are updated despite no other property changes. It appears that using no-tracking queries might be the only viable solution. However, we're wondering why the SaveChanges method updates the modification time and concurrency stamp even when the entity state is unchanged. Since our queries were generated using ABP Suite, modifying all of them to use no-tracking would require significant effort, making it an impractical option at this stage. Could you assist us in resolving this issue?
25 Answer(s)
-
0
hi
We're encountering concurrency errors when making parallel requests, even when the entity remains unmodified.
What entity changed?
Can you share some code?
The entity will be changed if its child entities have changed.
AbpEntityChangeOptions => PublishEntityUpdatedEventWhenNavigationChanges
Thanks.
-
0
We are retrieving configuration data from the database and using it to create an entity. For instance, we query the task type from the database and utilize its configuration to create a task item and insert it. However, when we attempt to insert the task, we encounter the following concurrency exception:
There is an entry which is not saved due to a concurrency exception: TaskType {Id: 8c6fb91c-177b-d1a0-97ea-3a17acd7ce44} Modified FK {AdviceTypeId: <null>} FK {TaskRequestTypeId: c5522fb7-64df-20b1-00af-3a17acd79a32}
We have not modified any details of the task type in the API. The issue is resolved when we use IReadOnlyRepository to fetch the task type. However, given that we have numerous queries spread throughout the system, modifying them all is not a feasible solution at this stage.
-
0
hi
Can you share the two entity class code?
TaskType
andTask
You can also
Using the DisableTracking extension method
to do the same thing asIReadOnlyRepository
https://abp.io/docs/9.0/framework/architecture/domain-driven-design/repositories#repository-extension-methods-for-change-tracking
Thanks.
-
0
-
0
hi
We will publish an event and update the entity when a navigation property of an entity has changed
But you can disable it for a specific entity.
Please try to add
MyAbpEfCoreNavigationHelper
to your EF Core project.using Microsoft.EntityFrameworkCore.ChangeTracking; using Volo.Abp.DependencyInjection; using Volo.Abp.EntityFrameworkCore.ChangeTrackers; using Volo.Abp.OpenIddict.Tokens; [Dependency(ReplaceServices = true)] [ExposeServices(typeof(AbpEfCoreNavigationHelper))] public class MyAbpEfCoreNavigationHelper : AbpEfCoreNavigationHelper { public override void ChangeTracker_Tracked(object? sender, EntityTrackedEventArgs e) { if (e.Entry.Entity.GetType() == typeof(TaskType)) { return; } base.ChangeTracker_Tracked(sender, e); } public override void ChangeTracker_StateChanged(object? sender, EntityStateChangedEventArgs e) { if (e.Entry.Entity.GetType() == typeof(TaskType)) { return; } base.ChangeTracker_StateChanged(sender, e); } }
And we add a selector to ignore some entities >= 9.1.1
https://github.com/abpframework/abp/pull/22315/files
-
0
-
0
hi
We have a lot of entities similar to this, so should we configure this for every entity?
You can ignore them(
TaskTypes
) inMyAbpEfCoreNavigationHelper
Or set
PublishEntityUpdatedEventWhenNavigationChanges
tofalse
ofAbpEntityChangeOptions
to keep the previous behavior. -
0
Hi,
I have tried upgrading v9.1.0 using abpupdate but couldn't find IgnoredNavigationEntitySelectors property. Is there a newer version where this property is available?
We have a microservices solution and heavily rely on events, so we are not confident setting PublishEntityUpdatedEventWhenNavigationChanges to false as it was defaulted to true in the previous version. Looks like the change to update the modification time came from this PR. https://github.com/abpframework/abp/pull/20012/files#diff-33b18ab38146b084012e294cf1639bbce7e8cc903594b83e3beee5b49193af1f. We don't want to disable PublishEntityUpdatedEventWhenNavigationChanges as this might impact other areas of our project.
-
0
hi
Please update the package to
9.1.1
. TheIgnoredNavigationEntitySelectors
will be available.Thanks.
-
0
hi
abp update --version 9.1.1
Or
You can search and replace the abp & Volo package version in
*.csproj
files globally.ABP & VOLO to
9.1.1
LeptonX to4.1.1
-
0
Thank you. We will try updating to 9.1.1.
Will this change in the PR(https://github.com/abpframework/abp/pull/20012/files#diff-33b18ab38146b084012e294cf1639bbce7e8cc903594b83e3beee5b49193af1f.) result in updating the modification time and concurrency stamp of all ef core tracked entities even if the navigation properties are not updated?
-
0
hi
Framework will skip it : https://github.com/abpframework/abp/blob/rel-9.1/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs#L274
You can try it.
Thanks.
-
0
Ignoring all entities affected by this issue is not a viable option. For instance, when creating a new version of an entity object, we first load the existing entity from the database, copy its details, and insert the new object into the database. Since the new version might have no direct relationship to the original entity, would this process still trigger an update to the concurrency stamp of the existing entity? We don't want to ignore the entity because we may want to trigger events when navigation properties change for that entity.
-
0
hi
Since the new version might have no direct relationship to the original entity, would this process still trigger an update to the concurrency stamp of the existing entity?
No, it will only trigger for the navigation property.
-
0
Hi, we implemented the solution for task type successfully. However, as I previously mentioned, with approximately 20 microservices and hundreds of entities, manually configuring each one and retesting is not feasible at this stage. We urgently need a solution for this, as our deadlines are fast approaching.
-
0
hi
we implemented the solution for task type successfully.
Are you using
IgnoredNavigationEntitySelectors
? -
0
yes, we tested by upgrading to 9.1.1 and ignored TaskType
-
0
hi
We can only modify the code to resolve this issue. There is no simpler way.
hundreds of entities
Only entities with
1-n
relationships may get concurrency exceptions. Not all entities. -
0
We tried the following code to ignore all entites.
Configure<AbpEntityChangeOptions>(options => { options.IgnoredNavigationEntitySelectors.Add("DisableAllEntity", _ => true); });
Do you think this could have any unintended consequences?
-
0
You can consider handling concurrent exceptions rather than disabling them. You can catch exceptions and then retry.
-
0
But I don't want to update task type when task item is inserted or modified as TaskType is an AggregateRoot. I believe the concurrency stamp and modification time of an aggregate root should not be updated when a related aggregate root changes.
This adjustment would be reasonable if the child entity were an AuditedEntity. For instance, in the case of an Order and Order Items, it might be necessary to update the modification time and concurrency stamp of the Order when an Order Item is inserted or modified. In such scenarios, I would extend OrderItem from AuditedEntity rather than AuditedAggregateRoot.
I believe this is a bug with abp code.
-
0
hi
You can override the
PublishEventsForChangedEntityOnSaveChangeAsync
ofAbpDbContext
and skip these lines.if (entityEntry.State == EntityState.Unchanged) { ApplyAbpConceptsForModifiedEntity(entityEntry, true); }
I will add an option to skip this in the next version.
-
0
I will add an option to skip this in the next version.
https://github.com/abpframework/abp/pull/22752
-
0
I really appreciate your swift reply! Is there a scheduled timeline for its release?
-
0
hi
It will be available on abp 9.2.0.
9.2.0 due by April 29, 2025