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

Bug when deleting parent record, CascadeDelete is set to false and was supposed to clear the reference to null #799

Open
burningice2866 opened this issue Mar 10, 2022 · 0 comments
Labels

Comments

@burningice2866
Copy link
Contributor

burningice2866 commented Mar 10, 2022

Consider this datatype

public interface ISubscriptionPayment : IData
{
    [StoreFieldType(PhysicalStoreFieldType.Integer)]
    [ImmutableFieldId("ce93accd-2892-4407-ba3c-1d899a93c875")]
    int Id { get; set; }

    [StoreFieldType(PhysicalStoreFieldType.Integer, IsNullable = true)]
    [ImmutableFieldId("33ae5a3a-5155-481c-abe5-4e2ee7a6e806")]
    [ForeignKey(typeof(ISubscriptionSignup), nameof(ISubscriptionSignup.SubscriptionId), AllowCascadeDeletes = false, NullReferenceValue = null)]
    int? SubscriptionId { get; set; }
}

When i delete the parent ISubscriptionSignup record, i expect the delete to happen successfully and SubscriptionId on all child records to be set to null.

Instead i get the error One of the given data items is referenced by one or more data items that do not allow cascade delete. and after some debugging through the callstacks i end up here

foreach (var refereeInfo in notOptionalReferences)
{
if (!refereeInfo.Item2.AllowCascadeDeletes)
{
throw new InvalidOperationException("One of the given data items is referenced by one or more data items that do not allow cascade delete.");
}
}
and here
public bool IsOptionalReference
{
get { return IsNullableString || SourcePropertyInfo.PropertyType == typeof (Guid?); }
}
.

Clearly the OptionalReference is being resolved wrong and naively expects that such thing can only happen using string or nullable guids.

The correct way would to look at any nullable type, not only guid.

@napernik napernik added the bug label Mar 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants