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

SQLite Error 19: 'FOREIGN KEY constraint failed #8

Open
rcisneros138 opened this issue Feb 22, 2024 · 14 comments
Open

SQLite Error 19: 'FOREIGN KEY constraint failed #8

rcisneros138 opened this issue Feb 22, 2024 · 14 comments

Comments

@rcisneros138
Copy link

Hello,

We have an Umbraco Commerce instance for an Umbraco cloud implementation.

We are running into an issue where the deploy package breaks the ability for us to create a store or update the Umbraco Schema. Here is the error we are getting on run locally.

{ "Date": "2024-02-22T10:16:53.273691-06:00", "Message": "SQLite Error 19: 'FOREIGN KEY constraint failed'.", "Ex": { "SqliteErrorCode": 19, "SqliteExtendedErrorCode": 787, "IsTransient": false, "SqlState": null, "BatchCommand": null, "ErrorCode": -2147467259, "Message": "SQLite Error 19: 'FOREIGN KEY constraint failed'.", "Data": {}, "InnerException": null, "HelpLink": null, "Source": "Umbraco.Commerce.Infrastructure", "HResult": -2147467259, "StackTrace": " at Umbraco.Commerce.Infrastructure.Resiliency.PollyExecutionStrategyBase.Execute[TResult](Func1 operation, Func1 verifySucceeded)\n at Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.Execute(IUnitOfWorkOptions options, Action1 action)\n at Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.Execute(Action1 action)\n at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceEmailTemplateServiceConnector.Pass2(ArtifactDeployState2 state, IDeployContext context)\n at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceEmailTemplateServiceConnector.Process(ArtifactDeployState2 state, IDeployContext context, Int32 pass)\n at Umbraco.Deploy.Infrastructure.Connectors.ServiceConnectors.ServiceConnectorBase3.Process(ArtifactDeployState dart, IDeployContext context, Int32 pass)\n at Umbraco.Deploy.Infrastructure.Environments.CurrentEnvironment.ProcessArtifacts(IEnumerable1 arts, String ownerEmail, IDeployContext context, CancellationToken token)" }, "Sender": "Umbraco.Deploy.Infrastructure.Work.WorkItems.DiskReadWorkItem" }

A few notes. We are on the latest packages for commerce and deploy. We also were forced to split the sqlite DB locally due to the ongoing Lock issue that occurs when using a sinple sqlite db.

I would appreciate any help on this as I would like to have a single store instance to pass along our environments.

Raymond

@mattbrailsford
Copy link
Contributor

Hey, so the only foreign key constraint on the email template should be the store ID. This would suggest that maybe the store wasn't deployed.

Have you tried re-exporting from the deploy dashboard in settings to make sure all uda files are on disk?

@rcisneros138
Copy link
Author

@mattbrailsford Thanks for the reply.

I went ahead and wipes out the stores on my dev environment and local. I also removed all store udas.

I'm now getting this error when attempting to restore locally:

ystem.ArgumentNullException: Value cannot be null. (Parameter 'o') at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName) at Newtonsoft.Json.Linq.JToken.FromObjectInternal(Object o, JsonSerializer jsonSerializer) at Newtonsoft.Json.Linq.JObject.FromObject(Object o, JsonSerializer jsonSerializer) at Newtonsoft.Json.Linq.JObject.FromObject(Object o) at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceShippingMethodServiceConnector.GetArtifact(GuidUdi udi, ShippingMethodReadOnly entity) at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceEntityServiceConnectorBase2.GetArtifact(GuidUdi udi, IContextCache contextCache)
at Umbraco.Deploy.Infrastructure.Connectors.ServiceConnectors.ServiceConnectorBase3.Umbraco.Cms.Core.Deploy.IServiceConnector.GetArtifact(Udi udi, IContextCache contextCache) at Umbraco.Deploy.Infrastructure.Environments.CurrentEnvironment.GetSignatures(IEnumerable1 udis, IContextCache contextCache, CancellationToken token)
at Umbraco.Deploy.Infrastructure.Environments.CurrentEnvironment.ReviewManifest(Guid sessionId, Manifest manifest)
at Umbraco.Deploy.Infrastructure.Environments.CurrentEnvironment.ReviewManifestAsync(Guid sessionId, Manifest manifest, CancellationToken token)
at Umbraco.Deploy.Infrastructure.Work.WorkItems.DiskReadWorkItem.Proceed(List1 artifacts, Manifest manifest) at Umbraco.Deploy.Infrastructure.Work.WorkItems.DiskReadWorkItem.ExecuteAsyncSub(IWorkContext context, List1 resume, CancellationToken token)
at Umbraco.Deploy.Infrastructure.Work.WorkItems.DiskR`

This is a weird once since it seems related to the shipping method, but the shipping method .uda looks fine.

Any guidance as to what I might be missing on this?

thanks again,

Raymond

@rcisneros138
Copy link
Author

Well of course minutes after I post this I found the solution. Looks like I need to assign a country to the shipping method and it seemed to work.

@rcisneros138
Copy link
Author

welp, though I have this working locally, Dev seems to be broken for the lack of a better term.

all of .uda's exist on disk in dev :
image

and the deployment process in back office seems to have completed as well ( I ran it a couple times):
image

No store appears when expanding the dropdown of stores.

I brought the code down locally and am seeing an error that specifically seems to target the shipping method:
Umbraco.Deploy.Core.Exceptions.ProcessArtifactException: Process pass #2 failed for artifact umb://umbraco-commerce-shipping-method/aef018dd9e2c40dbbf25018dd1f7493d. ---> System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.ArgumentNullException: Value cannot be null. (Parameter 'o') at Newtonsoft.Json.Utilities.ValidationUtils.ArgumentNotNull(Object value, String parameterName) at Newtonsoft.Json.Linq.JToken.FromObjectInternal(Object o, JsonSerializer jsonSerializer) at Newtonsoft.Json.Linq.JObject.FromObject(Object o, JsonSerializer jsonSerializer) at Newtonsoft.Json.Linq.JObject.FromObject(Object o) at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceShippingMethodServiceConnector.GetArtifact(GuidUdi udi, ShippingMethodReadOnly entity) at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceEntityServiceConnectorBase2.GetArtifact(Object o, IContextCache contextCache)
at Umbraco.Deploy.Infrastructure.Connectors.ServiceConnectors.ServiceConnectorBase3.Umbraco.Cms.Core.Deploy.IServiceConnector.GetArtifact(Object o, IContextCache contextCache) at Umbraco.Commerce.Deploy.Composing.UmbracoCommerceDeployComponent.GetEntityArtifact(EntityBase entity) at Umbraco.Commerce.Deploy.Composing.UmbracoCommerceDeployComponent.<InitializeDiskRefreshers>b__10_6(ShippingMethodSavedNotification e) at System.RuntimeMethodHandle.InvokeMethod(Object target, Void** arguments, Signature sig, Boolean isConstructor) at System.Reflection.MethodBaseInvoker.InvokeDirectByRefWithFewArgs(Object obj, Span1 copyOfArgs, BindingFlags invokeAttr)
--- End of inner exception stack trace ---
at Umbraco.Commerce.Infrastructure.Resiliency.PollyExecutionStrategyBase.Execute[TResult](Func1 operation, Func1 verifySucceeded)
at Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.Execute(IUnitOfWorkOptions options, Action1 action) at Umbraco.Commerce.Core.UmbracoCommerceUnitOfWorkProvider.Execute(Action1 action)
at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceShippingMethodServiceConnector.Pass2(ArtifactDeployState2 state, IDeployContext context) at Umbraco.Commerce.Deploy.Connectors.ServiceConnectors.UmbracoCommerceShippingMethodServiceConnector.Process(ArtifactDeployState2 state, IDeployContext context, Int32 pass)
at Umbraco.Deploy.Infrastructure.Connectors.ServiceConnectors.ServiceConnectorBase3.Process(ArtifactDeployState dart, IDeployContext context, Int32 pass) at Umbraco.Deploy.Infrastructure.Environments.CurrentEnvironment.ProcessArtifacts(IEnumerable1 arts, String ownerEmail, IDeployContext context, CancellationToken token)
--- End of inner exception stack trace ---
at Umbraco.Deploy.Infrastructure.Environments.CurrentEnvironment.ProcessArtifacts(IEnumerable1 arts, String ownerEmail, IDeployContext context, CancellationToken token) at Umbraco.Deploy.Infrastructure.Environments.CurrentEnvironment.ProcessPackageAsync(Guid sessionId, Package package, CancellationToken token) at Umbraco.Deploy.Infrastructure.Work.WorkItems.DiskReadWorkItem.Proceed(List1 artifacts, Manifest manifest)
at Umbraco.Deploy.Infrastructure.Work.WorkItems.DiskReadWorkItem.ExecuteAsyncSub(IWorkContext context, List1 resume, CancellationToken token) at Umbraco.Deploy.Infrastructure.Work.WorkItems.DiskReadWorkItem.ExecuteAsync(IWorkContext context, CancellationToken token)

This is where I'm stuck for now.

@mattbrailsford
Copy link
Contributor

Ok, I think I know where the issue lies here.

We've recently done some updates around Shipping Methods so I think this is from these updates. It looks like we don't null check a new property and so it fails when it attempts to serialize it.

I'll prep a nightly build and you can test that to see if it resolves things for you.

@mattbrailsford
Copy link
Contributor

So there is a 13.1.1--preview2 on the nightly feed now. If you'd like to give that a try and see if it resolves the issue for you.

Details on how to use the nightly feed can be found here https://docs.umbraco.com/umbraco-cms/fundamentals/setup/install/installing-nightly-builds

@rcisneros138
Copy link
Author

@mattbrailsford Really appreciate the quick response. I removed the package for now so my team can continue development. I will re-try later tonight and give you an update.

thanks!

@rcisneros138
Copy link
Author

rcisneros138 commented Mar 1, 2024

@mattbrailsford sorry for the late response. I managed to get around to this just now and installed the nightly package on my project. I don't see the error occurring locally, however I still can't seem to get the store to show in our cloud dev environment. The deployment operation completes just fine, and the .uda's seem to exist on the server. I'm wondering if it has something to do with it being a nightly package in cloud?

@mattbrailsford
Copy link
Contributor

@rcisneros138 are there any errors in the tracelog? Also, if you check the dev db, is there a store entry in the database?

@rcisneros138
Copy link
Author

@mattbrailsford So we already have a store on each environment. Before I pushed the change to my project to include the deploy package, I deleted the store in dev through back office. I then Created a new store locally, ensuring that all of the .uda were generated and pushed that up to dev.

Once on dev, the deploy occurs just fine and I see the .uda's on the server, but no store will load in the settings section. I didn't think to check the DB. So i'm going to go through the process again tonight and cross reference what exists in the DB each step of the way.

@mattbrailsford
Copy link
Contributor

I’ve got a feeling that because we soft delete entities when the store is deploying it might be deploying to a deleted store with the same ID.

@rcisneros138
Copy link
Author

rcisneros138 commented Mar 9, 2024

@mattbrailsford I think you might be onto something. I'm obviously not familiar with how the source code works, but it seems like like "deleting" a store isn't removing it from the DB.

I created a "demo store" and then deleted it. In the DB I queried the stores table and not only see the "demo store", but all of the stores I had created and deleted.

image

Can you provide guidance on how to delete or remove stores completely so that I can have a sort of "clean slate"? Could I simply delete the entry in the store table?

thanks,

Raymond

@rcisneros138
Copy link
Author

Also, I would like to mention that the latest build has allowed me to create a store and sync it between environments. I create a store with an alias I had not used before and it seems to function now.

@mattbrailsford
Copy link
Contributor

mattbrailsford commented Mar 10, 2024

Hey Raymond,

You'd need to delete all the linked entities too, so all the order statuses, payment methods, shipping methods, countries, currencies, tax classes etc. If you are right at the start of your setup, it might be easier to drop all the database tables and rerun the migration scripts to recreate the tables from fresh.

We soft delete these as we need to ensure data integrity so if an order was placed with a payment method that was later deleted, we still need to display the payment method for the historic data. This usually means if you query for an entity explicitly via it's ID, it will return it if it's deleted or not. So I can see why that would be a problem here, as Umbraco Commerce Deploy will load the store explicitly and so could be loading the deleted store.

I'm glad the latest release is working well for you 👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants