U4-1624 - ContentService SaveAndPublish not setting ID on newly created Content

Created by Tom Dudfield 01 Feb 2013, 16:04:03 Updated by Tom Dudfield 08 Feb 2013, 10:57:14

Relates to: U4-1648

When creating new content, if I call contentService.Save(content) the ID of the content is set after the save. However if I call contentService.SaveAndPublish(content) the ID of the content isn't set. This behaviour doesn't seem correct, I would expect the ID to be set in both scenarios.


Morten Christensen 01 Feb 2013, 17:03:04

Would it be possible for you to post a bit of your code? Think I'm missing the context because it seems unlikely that the behavior of Save would be different (in Save vs. SaveAndPublish) as the two methods are using the same internal repository for persisting the content object to the db.

Morten Christensen 02 Feb 2013, 08:17:52

After some more thought I think I know what is causing this. But just to confirm the content you are trying to SaveAndPublish does that have any ancestors that are not published or a mandatory property that is blank or null?

Tom Dudfield 04 Feb 2013, 12:08:31

I can confirm that the property isn't mandatory.

Please refer to line 98, it was SaveAndPublish https://github.com/TomDudfield/Umbraco.Auto.Documents/blob/feature/v6/AutoDocuments/AutoDocuments.cs

Morten Christensen 04 Feb 2013, 12:41:44

So currently you do Save and then Publish - did you verify that this approach does in fact publish the content passed in? Does the Publish method return true or false?

Tom Dudfield 04 Feb 2013, 14:43:33

Good point the publish returns false, however I'm not sure why as there are no mandatory fields and the parent item is already published.

Morten Christensen 04 Feb 2013, 14:48:57

The conditions for Publish is that all ancestors are published (except for the system root with id -1 of course), that content is valid (meaning no blank/null mandatory fields) and that the status of the content is not Expired, AwaitingRelease or Trashed. All of these checks are logged upon published, so you should be able to find some info in the UmbracoTraceLogs.txt file in /App_Data/Logs/

Tom Dudfield 04 Feb 2013, 15:03:40

Looking at the log I see the following error, I've checked and it happens for every doc type not just the one I was trying earlier so it seems I have more of a fundamental issue

2013-02-04 14:56:59,496 [6] INFO Umbraco.Core.Services.ContentService - [Thread 5] Content 'Blog' with Id '1107' could not be published because of invalid properties.

Morten Christensen 04 Feb 2013, 15:07:14

If you have it in a sql ce database I'd be happy to take a look and see if I can spot the issue - Or run the code from your github repo if that is what produces the result..?

Tom Dudfield 04 Feb 2013, 15:12:13

The database is on azure, so you can connect directly to that using SSMS. Is there a way I can send you the credentials?

Morten Christensen 06 Feb 2013, 08:51:22

Tom, I think this issue might be related to U4-1648 which I'm gonna look into today.

Tom Dudfield 06 Feb 2013, 09:04:02

Thanks, after more investigation that sounds very similar to my issue, my documents were setup in a similar way.

Morten Christensen 06 Feb 2013, 11:29:25

Hi Tom, the issue has been fixed for version 6.0.1 which is due out March 1st, but I have pushed a build of the recent changes so you can use the following nightly build to correct this issue: http://nightly.umbraco.org/umbraco%206.0.1/UmbracoCms.6.0.1-build.7.zip

Just overwrite the asssemblies with the ones from the bin folder in the above zip, and you should be good to go.

Tom Dudfield 06 Feb 2013, 11:52:57

Thanks Morten

Tom Dudfield 08 Feb 2013, 10:57:14

I can confirm, that using the updated dlls my issue is now resolved. Thanks

Priority: Normal

Type: Bug

State: Fixed

Assignee: Morten Christensen

Difficulty: Normal


Backwards Compatible: True

Fix Submitted:

Affected versions: 6.0.0

Due in version: 6.0.1


Story Points: