nathanwoulfe / Flip

Other
5 stars 0 forks source link

SQLite Error 19: `FOREIGN KEY constraint failed`. #5

Open markadrake opened 4 months ago

markadrake commented 4 months ago

Hello Nathan đź‘‹,

I download the latest version of your Flip package (I believe it's 13.0.0) and I'm using the latest patched version of Umbraco 13.3.2 (it's been a fun week).

I really liked how easy it was to use your package. I was thrown for a loop on the user group permission (I must have skipped reading that–but nice touch!)

Unfortunately, when I went to convert a content node from one type to the next I received this error.

image

An error occurred
SQLite Error 19: 'FOREIGN KEY constraint failed'.

Exception Details
Microsoft.Data.Sqlite.SqliteException, Microsoft.Data.Sqlite, Version=8.0.1.0, Culture=neutral, PublicKeyToken=adb9793829ddae60: SQLite Error 19: 'FOREIGN KEY constraint failed'.

The stacktrace:

at Microsoft.Data.Sqlite.SqliteException.ThrowExceptionForRC(Int32 rc, sqlite3 db)
   at Microsoft.Data.Sqlite.SqliteDataReader.NextResult()
   at Microsoft.Data.Sqlite.SqliteCommand.ExecuteReader(CommandBehavior behavior)
   at StackExchange.Profiling.Data.ProfiledDbCommand.ExecuteNonQuery() in C:\projects\dotnet\src\MiniProfiler.Shared\Data\ProfiledDbCommand.cs:line 261
   at Umbraco.Cms.Infrastructure.Persistence.FaultHandling.RetryPolicy.ExecuteAction[TResult](Func`1 func)
   at NPoco.Database.ExecuteNonQueryHelper(DbCommand cmd)
   at NPoco.Database.Execute(String sql, CommandType commandType, Object[] args)
   at NPoco.Database.Execute(Sql Sql)
   at NPoco.Database.Execute(String sql, Object[] args)
   at NPoco.Database.UpdateImpAsync(String tableName, String primaryKeyName, Object poco, Object primaryKeyValue, IEnumerable`1 columns, Boolean sync)
   at NPoco.AsyncHelper.RunSync[T](Task`1 task)
   at NPoco.Database.Update(String tableName, String primaryKeyName, Object poco, Object primaryKeyValue, IEnumerable`1 columns)
   at NPoco.Database.Update(Object poco, Object primaryKeyValue, IEnumerable`1 columns)
   at NPoco.Database.Update(Object poco)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.DocumentRepository.PersistUpdatedItem(IContent entity)
   at Umbraco.Cms.Core.Cache.DefaultRepositoryCachePolicy`2.Update(TEntity entity, Action`1 persistUpdated)
   at Umbraco.Cms.Infrastructure.Persistence.Repositories.Implement.EntityRepositoryBase`2.Save(TEntity entity)
   at Umbraco.Cms.Core.Services.ContentService.Save(IContent content, Nullable`1 userId, ContentScheduleCollection contentSchedule)
   at Flip.Services.Implement.FlipService.TryChangeContentType(ChangeDocumentTypeModel model, String& message)
   at Flip.Controllers.ApiController.ChangeContentType(ChangeDocumentTypeModel model)
   at lambda_method8101(Closure, Object, Object[])
   at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.SyncActionResultExecutor.Execute(ActionContext actionContext, IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeActionMethodAsync()
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeNextActionFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
   at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.InvokeInnerFilterAsync()
--- End of stack trace from previous location ---
   at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeNextExceptionFilterAsync>g__Awaited|26_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
markadrake commented 4 months ago

This worked when I added a template to the target document type.

I'll leave it up to you to decide whether you think this issue should be addressed. Would you accept a small change to the readme to point out that your package requires user group permission, too?

Thank you for your work on this package!

nathanwoulfe commented 4 months ago

Hey @markadrake, I'm always open to contributions!

This is all largely experimental and will probably stop working at some point, but hey, it does the trick for now. Reflection to get internal methods is a bit cheeky but until CMS moves that cheese, I'll keep nibbling.

I can have a look too at some additional validation to ensure the target type has a template, or at least handle the cases where it doesn't.

Appreciate the kind words too!