PageTypeDefinition stopped automatically adding fields on certain environments

We’ve been working a while on a project and have been using the PageTypeDefinition system for creating page types. It has been working mostly fine with the exception that the “Overwrite” property seem to work only sometimes.

However now we ran into a breaking issue; We have a previously defined pagetype that works as a “Settings” object and includes fields for configuring the website. All the sudden fields stopped being added in our test environment but are added fine local environments. Is there a course of action to resolve this? We need to be able to add fields to that template as the project progress.

I don’t have much other information to give, the fields I tried to add was defined as “Settings”-fields, but other than that, they are regular fields.

Litium version: 6.1.2-patch-1806080803

Have you checked if you get any information in the log during application startup when pagetypes are created/modified?

I think we might have a lead on what has happened. The template had already been deployed to test once, and in the deploys that contains fields that aren’t being added. A field had been changed from “Content” to “Settings”. Also had “Overwrite = true”.

I’m guessing that there is a bug where Litium cannot handle fields being moved?

We’re seeing an crash in the error log saying that “Field already exists”, and I guess it just stops trying to update the template all together.

Modify or delete of fields from definition does not work without re-creating the pagetype.

Does it work if you first delete the field from Content from Litium backoffice?

I tried deleting the pages types and having them be recreated. New pages are created but no fields are added.
An exception can be found in the log like this;

2018-06-21 12:50:12.1898 [ERROR] [] Litium.Web.Mvc.Runtime.CreatePageTypesAndTemplates - Object reference not set to an instance of an object. Litium.Foundation.Data.DatabaseConnectionFailureException: Object reference not set to an instance of an object. ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Litium.Foundation.Data.MSSQL.Utilities.MSSQLUtilities.OpenConnection(SqlConnection openConnection)
   --- End of inner exception stack trace ---
   at Litium.Foundation.Data.MSSQL.Utilities.MSSQLUtilities.OpenConnection(SqlConnection openConnection)
   at Litium.Foundation.Data.MSSQL.Utilities.MSSQLUtilities.OpenCommand(SqlCommand sqlCommand, CommandType commandType, String commandText)
   at Litium.Foundation.Modules.CMS.Data.MSSQL.PageTypeDataProvider.GetPageType(String pageTypeName, Boolean includeStrings, Boolean includeTemplates, Boolean includeProperties, Boolean includeValues, SqlCommand openCommand)
   at Litium.Foundation.Modules.CMS.Data.MSSQL.PageTypeDataProvider.GetPageType(String pageTypeName, Boolean includeStrings, Boolean includeTemplates, Boolean includeProperties, Boolean includeValues)
   at Litium.Foundation.Modules.CMS.Cache.PageTypeCache.GetPageType(String pageTypeName)
   at Litium.Foundation.Modules.CMS.PageTypes.PageType.get_PossibleChildPageTypes()
   at Litium.Foundation.Modules.CMS.PageTypes.PageType.RemoveThisAsPossibleChildPageType(IEnumerable`1 pageTypes, PageTypeCollection allPageTypes, Boolean isUpdate, SecurityToken token)
   at Litium.Foundation.Modules.CMS.PageTypes.PageType.HandleParentsAndChildren(Boolean isUpdate, SecurityToken token)
   at Litium.Studio.Builders.CmsPageTypeExtensions.SetupParentPageTypes(PageTypeDefinition self, Boolean overwriteExisting)
   at Litium.Web.Mvc.Runtime.CreatePageTypesAndTemplates.<Start>b__5_0()
   at System.Threading.Tasks.Task.Execute()

When a pagetype is generated in Litium a row is added in the database-table Common.Settings and as Long as this row is there Litium will consider the pagetype as created and not re-create it again.

So if you want the pagetype to be re-created you need to

  1. delete the pagetype from backoffice
  2. delete its row from Common.Settings (key column contain the pagetype name)
  3. restart the application.

Thanks, I’ll give it a try.
But the page types are recreated, but the fields aren’t.

I will have a look if there is a lingering row that is causing issues. But should I also report this as a bug? It seems that when you remove a page, it should also be removed from that table? We’ve had a couple of these issues now.

Not really, you might want to remove a pagetype and not have it being re-created again, but it should not be partially re-created so that is a bug i think, please report it.

I guess that is a matter of taste. In my mind, if a template is removed in back office but kept in code, it should be re-created, no matter what. You should also delete the class.

If a page exists both in back office and code, the code needs to be the one true place for how the page type should be, otherwise it gets very confusing. I would even go that far to say that if a Page Type is created from code, it shouldn’t be possible to change it in back office. But I understand as features evolve etc…

I’ll report the bug, and write back here if the SQL fix worked.