Error restoring page

Hi, we have a weird problem with our CI and are a bit out of idea as to why.

We have a page type MetroStation. We want to create a page named MetroStation. I do that in the admin, execute a

dotnet run --kxp-ci-store --no-build  ```

No problem until there. We reset our database and run the ci with --kxp-ci-restore

All the other pages are back without any problem but we end up with this error

Query:
INSERT INTO Domain_MetroStation ([ContentItemDataID], [ContentItemDataCommonDataID], [ContentItemDataGUID], [DocumentName], [DocumentPageTitle], [DocumentPageDescription], [DocumentPageKeyWords])
VALUES (@ContentItemDataID, @ContentItemDataCommonDataID, @ContentItemDataGUID, @DocumentName, @DocumentPageTitle, @DocumentPageDescription, @DocumentPageKeyWords);

SELECT SCOPE_IDENTITY() AS [ID]

Caused exception:
Cannot insert explicit value for identity column in table 'Domain_MetroStation' when IDENTITY_INSERT is set to OFF.


Exception type: System.Exception
Stack trace:
   at CMS.DataEngine.AbstractDataConnection.HandleError(String queryText, Exception ex)
   at CMS.DataEngine.AbstractDataConnection.ExecuteScalar(String queryText, QueryDataParameters queryParams, QueryTypeEnum queryType, Boolean requiresTransaction)
   at CMS.DataEngine.GeneralConnection.ExecuteScalar(QueryParameters query)
   at CMS.DataEngine.DataQueryBase`1.GetScalarFromDBInternal()
   at CMS.DataEngine.DataQueryBase`1.GetScalarFromDB()
   at CMS.DataEngine.DataQueryBase`1.GetScalarResult()
   at CMS.DataEngine.DataQueryBase`1.ExecuteScalar()
   at CMS.DataEngine.DataQueryBase`1.GetScalarResult[T](T defaultValue)
   at CMS.DataEngine.DataClassDataSqlStore.<>c__DisplayClass2_0.<InsertSyncOrAsync>b__2()
   at CMS.DataEngine.SyncOrAsyncInvoker.InvokeSyncOrAsync[TResult](Boolean useAsync, Func`1 syncFunc, Func`1 asyncFunc)
   at CMS.DataEngine.DataClassDataSqlStore.InsertSyncOrAsync(Boolean useAsync, IDataClass dataClass, Boolean initializeId, CancellationToken cancellationToken)
   at CMS.DataEngine.DataClassDataSqlStore.Insert(IDataClass dataClass, Boolean initializeId)
   at CMS.DataEngine.AbstractInfoBase`1.InsertDataInternal()
   at CMS.DataEngine.AbstractInfoBase`1.<>c__DisplayClass68_0.<InsertDataSyncOrAsync>b__0()
   at CMS.DataEngine.SyncOrAsyncInvoker.InvokeSyncOrAsync(Boolean useAsync, Action syncAction, Func`1 asyncAction)
   at CMS.DataEngine.AbstractInfoBase`1.InsertDataSyncOrAsync(Boolean useAsync, CancellationToken cancellationToken)
   at CMS.DataEngine.AbstractInfoBase`1.InsertData()
   at CMS.DataEngine.AbstractInfoBase`1.GeneralizedInfoWrapper.InsertData()
   at CMS.DataEngine.AbstractInfoProvider`3.WithEvent[TBeforeEvent,TAfterEvent](Action action, IEnumerable`1 beforeEventHandlers, TBeforeEvent beforeEvent, IEnumerable`1 afterEventHandlers, Func`1 afterEventFactory)
   at CMS.DataEngine.AbstractInfoProvider`3.<>c__DisplayClass92_3.<SetInfoSyncOrAsync>b__8()
   at CMS.DataEngine.SyncOrAsyncInvoker.InvokeSyncOrAsync(Boolean useAsync, Action syncAction, Func`1 asyncAction)
   at CMS.DataEngine.AbstractInfoProvider`3.SetInfoSyncOrAsync(Boolean useAsync, TInfo info, CancellationToken cancellationToken)
   at CMS.DataEngine.AbstractInfoProvider`3.SetInfo(TInfo info)
   at CMS.DataEngine.AbstractInfoProvider`2.Set(TInfo info)
   at CMS.ContentEngine.Internal.ContentItemDataInfo.SetObject()
   at CMS.DataEngine.BaseInfo.GeneralizedInfoWrapper.SetObject()
   at CMS.ContinuousIntegration.Internal.FileSystemChangedObjectsByTypeJobBase.SetChangedObject(BaseInfo baseInfo)
   at CMS.ContentEngine.FileSystemUpsertContentItemDataByTypeJob.SetChangedObject(BaseInfo baseInfo)
   at CMS.ContinuousIntegration.Internal.FileSystemChangedObjectsByTypeJobBase.ProcessChangedObject(DeserializedObject deserializedObject, String logMessageFormat)

The page is created but not the values so it crashed when trying to open it in the CMS (as there's no line in metrostation...).

Weirdest, if I rename my page type, I have no error.

I tried creating the same pagetype in Dancing goat and no problem so the problem must be somewhere in our code.

Generated class has nothing fancy

/// <summary>
	/// Represents a page of type <see cref="MetroStation"/>.
	/// </summary>
	[RegisterContentTypeMapping(CONTENT_TYPE_NAME)]
	public partial class MetroStation : IWebPageFieldsSource, ISTMBasePage
	{
		/// <summary>
		/// Code name of the content type.
		/// </summary>
		public const string CONTENT_TYPE_NAME = "Domain.MetroStation";


		/// <summary>
		/// Represents system properties for a web page item.
		/// </summary>
		[SystemField]
		public WebPageFields SystemFields { get; set; }


		/// <summary>
		/// DocumentName.
		/// </summary>
		public string DocumentName { get; set; }


		/// <summary>
		/// DocumentPageTitle.
		/// </summary>
		public string DocumentPageTitle { get; set; }


		/// <summary>
		/// DocumentPageDescription.
		/// </summary>
		public string DocumentPageDescription { get; set; }


		/// <summary>
		/// DocumentPageKeyWords.
		/// </summary>
		public string DocumentPageKeyWords { get; set; }


		/// <summary>
		/// BasePageIsSiteMap.
		/// </summary>
		public bool BasePageIsSiteMap { get; set; }
	}

Neither does the table

USE [Domain.kentico]
GO

/****** Object:  Table [dbo].[Domain_MetroStation]    Script Date: 2026-02-10 10:38:45 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

CREATE TABLE [dbo].[Domain_MetroStation](
	[ContentItemDataID] [int] IDENTITY(1,1) NOT NULL,
	[ContentItemDataCommonDataID] [int] NOT NULL,
	[ContentItemDataGUID] [uniqueidentifier] NOT NULL,
	[DocumentName] [nvarchar](100) NOT NULL,
	[DocumentPageTitle] [nvarchar](max) NULL,
	[DocumentPageDescription] [nvarchar](max) NULL,
	[DocumentPageKeyWords] [nvarchar](max) NULL,
 CONSTRAINT [PK_Domain_MetroStation] PRIMARY KEY CLUSTERED 
(
	[ContentItemDataID] ASC
)WITH (PAD_INDEX = OFF, STATISTICS_NORECOMPUTE = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS = ON, ALLOW_PAGE_LOCKS = ON, OPTIMIZE_FOR_SEQUENTIAL_KEY = OFF) ON [PRIMARY]
) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY]
GO

ALTER TABLE [dbo].[Domain_MetroStation] ADD  CONSTRAINT [DEFAULT_Domain_MetroStation_ContentItemDataCommonDataID]  DEFAULT ((0)) FOR [ContentItemDataCommonDataID]
GO

ALTER TABLE [dbo].[Domain_MetroStation] ADD  CONSTRAINT [DEFAULT_Domain_MetroStation_ContentItemDataGUID]  DEFAULT ('00000000-0000-0000-0000-000000000000') FOR [ContentItemDataGUID]
GO

ALTER TABLE [dbo].[Domain_MetroStation] ADD  CONSTRAINT [DEFAULT_Domain_MetroStation_DocumentName]  DEFAULT (N'') FOR [DocumentName]
GO

ALTER TABLE [dbo].[Domain_MetroStation]  WITH CHECK ADD  CONSTRAINT [FK_Domain_MetroStation_ContentItemDataCommonDataID_CMS_ContentItemCommonData] FOREIGN KEY([ContentItemDataCommonDataID])
REFERENCES [dbo].[CMS_ContentItemCommonData] ([ContentItemCommonDataID])
GO

ALTER TABLE [dbo].[Domain_MetroStation] CHECK CONSTRAINT [FK_Domain_MetroStation_ContentItemDataCommonDataID_CMS_ContentItemCommonData]
GO


Would you have a clue ? I'm guessing we must be having a collision somewhere but hard to find where.

Have a great day

Tags:
CI/CD Content types SQL
0

Answers

This may or may not help, but when inserting on the identity column, you have to set the Identity Insert ON (and i would turn it back off after).

SET IDENTITY_INSERT [Domain_MetroStation] ON;
GO

INSERT INTO Domain_MetroStation ([ContentItemDataID], [ContentItemDataCommonDataID], [ContentItemDataGUID], [DocumentName], [DocumentPageTitle], [DocumentPageDescription], [DocumentPageKeyWords])
VALUES (@ContentItemDataID, @ContentItemDataCommonDataID, @ContentItemDataGUID, @DocumentName, @DocumentPageTitle, @DocumentPageDescription, @DocumentPageKeyWords);


SET IDENTITY_INSERT [Domain_MetroStation] OFF;
GO

If your insert query is part of your CI/CD but a custom script, put that in it and it should allow it.

0

Hi

Alas, no custom script. It's all genereted by the CI files so I have no control over it.

I'm doing more tests, there really seams to be a collision somewhere. If I rename the class (changing namespace and/or Name in the CMS), I have 0 error and everything works smoothly.

Feels like a DI problem where the CI process is not retrieving the good one but hard to track.

0

We use a suffix based naming convention for contenttypes to clearly distinguish their purpose:

  • Pages (website content): Suffix with Page
    Example: MetroStationPage
  • Reusable content (content hub items): Suffix with Content
    Example: MetroStationContent

This prevents naming conflicts, perhaps the one you are encountering in the CI/CD.

Could it be that in your reset-database there is an object with the same name "MetroStation"?

I guess the collision must be somewhere in that name "MetroStation" or perhaps you are running into this?

1

To response this discussion, you have to login first.