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

HiLoValueGenerator.GetNewLowValueAsync never gets called #19420

Closed
Torvin opened this issue Dec 29, 2019 · 2 comments · Fixed by #21261
Closed

HiLoValueGenerator.GetNewLowValueAsync never gets called #19420

Torvin opened this issue Dec 29, 2019 · 2 comments · Fixed by #21261
Labels
area-change-tracking closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Milestone

Comments

@Torvin
Copy link

Torvin commented Dec 29, 2019

Looks like HiLoValueGenerator.GetNewLowValueAsync never get called. Instead GetNewLowValue always gets called because of the bug in HiLoValueGenerator.

Looks like HiLoValueGenerator overrides the worng pair of methods: Next/NextAsync instead of NextValue/NextValueAsync. Having 2 pairs of overridable methods is really confusing, I guess that's why this mistake was made.

Steps to reproduce

Configure your own HiLoValueGenerator, then try calling _dbContext.AddAsync().

Expected: GetNewLowValueAsync gets called.

Actual: GetNewLowValue gets called instead. Stack trace:

MyHiLoValueGenerator.GetNewLowValue()
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ValueGeneration.HiLoValueGeneratorState.Next<long>(System.Func<long> getNewLowValue)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ValueGeneration.HiLoValueGenerator<long>.Next(Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry entry)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator<long>.NextValueAsync(Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry entry, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ValueGeneration.ValueGenerator.NextAsync(Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntry entry, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.ValueGenerationManager.GenerateAsync(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry entry, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry.SetEntityStateAsync(Microsoft.EntityFrameworkCore.EntityState entityState, bool acceptChanges, bool modifyProperties, Microsoft.EntityFrameworkCore.EntityState? forceStateWhenUnknownKey, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.PaintActionAsync(Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntryGraphNode<(Microsoft.EntityFrameworkCore.EntityState TargetState, Microsoft.EntityFrameworkCore.EntityState StoreGenTargetState, bool Force)> node, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityEntryGraphIterator.TraverseGraphAsync<System.ValueTuple<Microsoft.EntityFrameworkCore.EntityState, Microsoft.EntityFrameworkCore.EntityState, bool>>(Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntryGraphNode<(Microsoft.EntityFrameworkCore.EntityState, Microsoft.EntityFrameworkCore.EntityState, bool)> node, System.Func<Microsoft.EntityFrameworkCore.ChangeTracking.EntityEntryGraphNode<(Microsoft.EntityFrameworkCore.EntityState, Microsoft.EntityFrameworkCore.EntityState, bool)>, System.Threading.CancellationToken, System.Threading.Tasks.Task<bool>> handleNode, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.ChangeTracking.Internal.EntityGraphAttacher.AttachGraphAsync(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry rootEntry, Microsoft.EntityFrameworkCore.EntityState targetState, Microsoft.EntityFrameworkCore.EntityState storeGeneratedWithKeySetTargetState, bool forceStateWhenUnknownKey, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.DbContext.SetEntityStateAsync(Microsoft.EntityFrameworkCore.ChangeTracking.Internal.InternalEntityEntry entry, Microsoft.EntityFrameworkCore.EntityState entityState, System.Threading.CancellationToken cancellationToken)
Microsoft.EntityFrameworkCore.dll!Microsoft.EntityFrameworkCore.DbContext.AddAsync<WikiFountain.Models.Editathon>(WikiFountain.Models.Editathon entity, System.Threading.CancellationToken cancellationToken)

Further technical details

EF Core version: 3.1.0
Target framework: .NET Core 3.1

@Torvin
Copy link
Author

Torvin commented Dec 29, 2019

As a workaround you can override the proper method in your HiLoValueGenerator manually:

protected override async ValueTask<object> NextValueAsync(EntityEntry entry, CancellationToken cancellationToken = default)
    => await base.NextAsync(entry, cancellationToken);

@ajcvickers
Copy link
Member

See also #20671--make sure the docs are accurate and helpful.

ajcvickers added a commit that referenced this issue Jun 14, 2020
@ajcvickers ajcvickers added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Jun 14, 2020
ajcvickers added a commit that referenced this issue Jun 15, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0, 5.0.0-preview7 Jun 22, 2020
@ajcvickers ajcvickers modified the milestones: 5.0.0-preview7, 5.0.0 Nov 7, 2020
@ajcvickers ajcvickers removed their assignment Sep 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-change-tracking closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. customer-reported type-bug
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants