Error creating custom content type

Topics: Troubleshooting
Jun 21, 2011 at 8:41 PM

I'm creating a new module which defines a new content type. The content type is creatable and consists of the CommonPart plus my custom part, which contains 3 string properties plus an ImageField (using Sebastien's Contrib.ImageField module). I created the standard driver and handler for the part, and the EditorTemplate view. The new type shows up in the admin menu under the "New" menu and displays the editor template correctly. Everything looks good but when I enter some data in the fields and click the Save button I get the error below (I'm running Orchard 1.1). Any ideas? I'm not sure why it's trying to create an IndexingTaskRecord as I didn't tell it to index this content type. I even tried disabling the Search and Indexing features but that didn't help.


Server Error in '/' Application.

null id in Orchard.Indexing.Models.IndexingTaskRecord entry (don't flush the Session after an exception occurs)

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: NHibernate.AssertionFailure: null id in Orchard.Indexing.Models.IndexingTaskRecord entry (don't flush the Session after an exception occurs)

Source Error: 

Line 45: 
Line 46:                 Logger.Debug("Final work for transaction being performed");
Line 47:                 _scope.Dispose();
Line 48:                 Logger.Debug("Transaction disposed");
Line 49:             }

Source File: D:\Dev\JobsBlog\src\Orchard\Data\TransactionManager.cs    Line: 47 

Stack Trace: 

[AssertionFailure: null id in Orchard.Indexing.Models.IndexingTaskRecord entry (don't flush the Session after an exception occurs)]
   NHibernate.Event.Default.DefaultFlushEntityEventListener.CheckId(Object obj, IEntityPersister persister, Object id, EntityMode entityMode) +267
   NHibernate.Event.Default.DefaultFlushEntityEventListener.GetValues(Object entity, EntityEntry entry, EntityMode entityMode, Boolean mightBeDirty, ISessionImplementor session) +95
   NHibernate.Event.Default.DefaultFlushEntityEventListener.OnFlushEntity(FlushEntityEvent event) +139
   NHibernate.Event.Default.AbstractFlushingEventListener.FlushEntities(FlushEvent event) +448
   NHibernate.Event.Default.AbstractFlushingEventListener.FlushEverythingToExecutions(FlushEvent event) +275
   NHibernate.Event.Default.DefaultFlushEventListener.OnFlush(FlushEvent event) +83
   NHibernate.Impl.SessionImpl.Flush() +509
   NHibernate.Transaction.DistributedTransactionContext.System.Transactions.IEnlistmentNotification.Prepare(PreparingEnlistment preparingEnlistment) +694

[TransactionAbortedException: The transaction has aborted.]
   System.Transactions.TransactionStateAborted.EndCommit(InternalTransaction tx) +17
   System.Transactions.CommittableTransaction.Commit() +453
   System.Transactions.TransactionScope.InternalDispose() +638
   System.Transactions.TransactionScope.Dispose() +2492
   Orchard.Data.TransactionManager.System.IDisposable.Dispose() in D:\Dev\JobsBlog\src\Orchard\Data\TransactionManager.cs:47
   Autofac.Core.Disposer.Dispose(Boolean disposing) +82
   Autofac.Util.Disposable.Dispose() +43
   Autofac.Core.Lifetime.LifetimeScope.Dispose(Boolean disposing) +31
   Autofac.Util.Disposable.Dispose() +43
   Orchard.Environment.<>c__DisplayClass2.<.ctor>b__0() in D:\Dev\JobsBlog\src\Orchard\Environment\WorkContextAccessor.cs:75
   Orchard.Environment.HttpContextScopeImplementation.System.IDisposable.Dispose() in D:\Dev\JobsBlog\src\Orchard\Environment\WorkContextAccessor.cs:80
   Orchard.Mvc.Routes.HttpAsyncHandler.EndProcessRequest(IAsyncResult result) in D:\Dev\JobsBlog\src\Orchard\Mvc\Routes\ShellRoute.cs:151
   System.Web.CallHandlerExecutionStep.System.Web.HttpApplication.IExecutionStep.Execute() +453
   System.Web.HttpApplication.ExecuteStep(IExecutionStep step, Boolean& completedSynchronously) +371

Jun 22, 2011 at 6:40 PM

That error can crop up indirectly when an error occurs during saving your content item (and a few other scenarios).

The exception might be in your logs files, or you can debug step thru your Update method and see if anything is getting thrown.

Unfortunately driver exceptions are swallowed kind of silently due to the way drivers are invoked.

Jun 22, 2011 at 7:08 PM

Ah, thanks. I don't know why I didn't check the logs. It seems my part is posting back to the driver with null values in all the properties. Now I gotta figure out why it's doing that ...

Jun 22, 2011 at 7:22 PM

Disregard that last comment ... I momentarily forgot how the Editor post method works in the driver. The values are actually coming through and being mapped properly by the TryUpdateModel method. But in the log NHibernate says it's trying to save null for one of the fields - don't know why that's happening.

Jun 22, 2011 at 7:35 PM

Okay, figured out the problem. When I defined the fields for my record's table in the Migration, I made one of them NOT NULL. Even though I was posting data for that field, I was getting the "... cannot be null ..." error, so I decided to try removing the NOT NULL constraint from the column. Now it works - it's saving the record and there is data in all of the columns. That seems to be a bug in Orchard. I'm using SQL CE if that matters. Maybe I should file this as a bug ...

Jun 22, 2011 at 7:52 PM
Edited Jun 22, 2011 at 7:53 PM

I advise avoiding non-nullables in content part records; partly because when someone is creating a draft, they just might not want to fill in all the fields! Also you don't know when some other module will try to create a content item of a particular type but not be aware that certain fields have to be filled. For instance my Media Garden module does this when it creates media content items.

Edit: What I forgot to include there is that you should of course still perform validation when Publishing content ...

Jun 22, 2011 at 9:35 PM

yes, please file a bug.