Draft added when trying to create and publish content programmatically

Vote:
 

Hi 

When trying to create a commerce content programmatically using code similar to this

var clone = content.CreateWritableClone<CustomProduct>();

//Update clone properties here 

var batch = new List<CustomProduct> { clone };

foreach (var branch in customModel.LanguageVersions)
{
    var branchContent =  contentRepository.Get<CustomProduct>(contentLink, branch.CultureInfo).CreateWritableClone<CustomProduct>();
   
    //update branchContent 
                
    batch.Add(updatedContent);
}

_contentRepository.Publish(batch);

I get *two* versions of my content instances for each language except the main one. 

One of them is in published state and created by "you", the other one is in a draft and created by "system".

When I open my product language instance I get to the draft by default where none of the properties were updated. If I then revert changes to published state - everything is correct.

Did anybody face the issue?

PS Tried to post a screenshot here. "Only users belong to partner companies are able to upload image files." - a bit annoying, isn't it?

#223961
Jun 08, 2020 16:28
Vote:
 

Have you tried debugging, and checking the content of batch just before calling _contentRepository.Publish(batch);?

#223964
Edited, Jun 08, 2020 18:42
Vote:
 

Yes, the content is okay. And actually if I revert to last published version then I get everything updated. So the problem is exactly in creating two instances (published and draft) for each language branch.

By the way, if I update the language instances one by one  contentRepository.Save(updatedContent, SaveAction.Publish, AccessLevel.NoAccess) I get the same issue. So this is not about batch only.

#224016
Edited, Jun 09, 2020 14:43
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.