U4-2112 - ImportDocumentType Failed when structure has values

Created by Kevin Jump 14 Apr 2013, 14:54:58 Updated by Morten Christensen 23 Apr 2013, 08:50:07

Relates to: U4-2137

Calling Packager.Installer.ImportDocumentType fails with the error below, when it is called with for an already existing document type - when the document type has "Allow Child NodeTypes" values set (which build the structure node in the XML)

[SqlCeException (0x80004005): A duplicate value cannot be inserted into a unique index. [ Table name = cmsContentTypeAllowedContentType,Constraint name = PK_cmsContentTypeAllowedContentType ]] System.Data.SqlServerCe.SqlCeCommand.ProcessResults(Int32 hr) +48 System.Data.SqlServerCe.SqlCeCommand.ExecuteCommandText(IntPtr& pCursor, Boolean& isBaseTableCursor) +297 System.Data.SqlServerCe.SqlCeCommand.ExecuteCommand(CommandBehavior behavior, String method, ResultSetOptions options) +646 System.Data.SqlServerCe.SqlCeCommand.ExecuteNonQuery() +21 Umbraco.Core.Persistence.Database.Insert(String tableName, String primaryKeyName, Boolean autoIncrement, Object poco) +1667 Umbraco.Core.Persistence.Database.Insert(Object poco) +51 Umbraco.Core.Persistence.Repositories.ContentTypeBaseRepository2.PersistUpdatedBaseContentType(ContentTypeDto dto, IContentTypeComposition entity) +4473 Umbraco.Core.Persistence.Repositories.ContentTypeRepository.PersistUpdatedItem(IContentType entity) +767 Umbraco.Core.Persistence.Repositories.RepositoryBase2.PersistUpdatedItem(IEntity entity) +48 Umbraco.Core.Persistence.UnitOfWork.PetaPocoUnitOfWork.Commit() +256 Umbraco.Core.Services.ContentTypeService.Save(IEnumerable`1 contentTypes, Int32 userId) +262 Umbraco.Core.Services.PackagingService.ImportContentTypes(XElement element, Int32 userId) +1101 umbraco.cms.businesslogic.packager.Installer.ImportDocumentType(XmlNode n, User u, Boolean ImportStructure) +53

  • This worked in previous versions (6.0.0/6.0.1) of Umbraco and Works in the v4 branch upto and including 4.11.6
  • this has been tested on nightly builds (upto 13)

Comments

Morten Christensen 14 Apr 2013, 15:45:34

Was this tested against latest nightly build of 6.0.4? As I mentioned in the thread on OUR I wrote a test for importing and then re-importing the same doc type with the same allowed doc type structure and this passed after making a few corrections to 6.0.4. The test was however written for the regular package install, but the ImportDocumentType method uses the same underlaying method, so not sure why it wouldn't work for you. But have you tried calling the install package method instead? Wondering if will give you another result?

Could you attach the XML that is causing problems? If its changed between imports then please add both. Thanks.


Kevin Jump 14 Apr 2013, 16:24:12

I tried it on Build 13 (10th April) shall i try on 15 ? (12th)


Morten Christensen 14 Apr 2013, 16:42:44

I don't remember when the changes was made, so let me try and reproduce the issue first. Just need to know if the imported XML was changed between imports or if it was the same in both tries?


Kevin Jump 14 Apr 2013, 16:44:32

yes, the same result in Nightly Build 15 of 6.0.4

the following XML is used

TestDocType TestDocType folder.gif folder.png a test False test TestDocType {code}

if you remove the node, then the calls work, changes get applied, etc...


Morten Christensen 20 Apr 2013, 14:05:30

Sorry, I can't reproduce this issue. I have tested this manually using the ImportDocumentType method on the umbraco.cms.businesslogic.packager.Installer class. I used the xml you pasted above, imported it, then imported it again and didn't encounter any issues. I can tried to edit the list of allowed child types in the UI and re-import, but still no issues.


Kevin Jump 20 Apr 2013, 20:01:44

Is this still true after an application restart ? the existing code I have calls Install.ImportDocumentType twice (once with import structure set to false & once true) This works on the first import - but fails next time (which is triggered by an app restart).

Looking at the latest source for 6.0.4, the ImportDocumentType function the "bool ImportStructure" variable is no longer acted upon, So I suspect that this is now redundant? however I don't understand how you can now import a set of document types and have the structure import correctly (what happens if the first doctype allows the yet uncreated doctypes to be childnodes?)


Morten Christensen 21 Apr 2013, 04:43:27

Yes, I also noticed the redundant structure param, but it shouldn't matter for this test though seeing as its a single import, but I'll look into how that param can be added to the new service.

I haven't tried doing an app restart and then import again. But I can try.

When you import doc types the structure is added as the last thing, so first all doc types are created or updated and then those with allowed child types are updated/saved again. So everything will have been created before adding the structure setting.


Morten Christensen 21 Apr 2013, 09:34:38

Success!! Finally managed to reproduce the issue. The problem occurred when the referenced and existing doc type was loaded instead of created (annoying thing is that I also have this in my unit test, but it kept the state from the first import, which is why it didn't end up creating duplicate entries in the AllowedContentTypes-list). The comparison of new and existing doc types in the structure was then invalid, so changed the comparison to ensure that duplicates are not added to the list of AllowedContentTypes.

I also added the option to determine if you want to import the structure as well or skip it. So the ImportStructure parameter on Installer.ImportDocumentType is valid again. Hopefully this means that we have re-aligned the imports in v6 to that of v4, so there are no funky surprises.


Priority: Normal

Type: Bug

State: Can't Reproduce

Assignee: Morten Christensen

Difficulty: Normal

Category:

Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.3, 6.0.4

Due in version:

Sprint:

Story Points:

Cycle: