Today in a category, which features support cases causing to pull my hair out, a very interesting issue I’ve had with a customer reporting that unapproved content was going live quite unexpectedly.

After witnessing the issue with my own eyes when an item just created and not pushed via workflow was magically showing up in production after a few minutes, I decided to investigation Sitecore configuration. This revealed a PublishAgent that was enabled to run frequently, but nothing else.

<agent type="Sitecore.Tasks.PublishAgent" method="Run" interval="00:01:00">

<param desc="source database">master</param>

<param desc="target database">web</param>

<param desc="mode (full or incremental)">incremental</param>

<param desc="languages">en, da</param>
</agent>

After reproducing this on a local single server instance, I’ve narrowed it down to the “languages” parameter being the issue.
By default all PublishAgents configured with both “English” and “Danish” languages processed. What happens within the PublishAgent is pretty interesting.

  1. The “languages” parameter (“en, da”) is parsed with the following code:
private static List<Language> ParseLanguages(string languages)  
{

List<Language> list = new List<Language>();

foreach (string str in languages.Split(new char[] { ',' }))

{

if (str.Length > 0)

{

**list.Add(Language.Parse(str.Trim()));
** }

}

return list;  
}
  1. Down below, the Parse() method calls Language.TryParse() which basically boils down to the following checks:
if (LanguageManager.IsValidLanguageName(name))

if (LanguageManager.LanguageRegistered(name))

if (LanguageManager.RegisterLanguage(name))

If all these checks pass, the language name is considered to be valid. What’s interesting here is that even languages that are not created/registered within Sitecore under /system/languages will be parsed successfully. In our case there is no language with ISO code “da” created/registered in Sitecore, however, as far as Language.TryParse() is concerned, this language is valid and will be passed onto the publisher.

The publisher will try and get an item in “da” language from ItemManager for further processing. Due to the nature of Sitecore to decouple items from versions, this operation will actually return an item. This item will be returned as “empty” or “naked” with no versions, but there will be an instance.

So the publisher will process this item and treat it as “approved” and publish it to the target database.

While we can speculate on whether this is expected behavior or not, there is an easy solution for this problem. Simply make sure your PublishAgent is not configured to process any languages that do not exist within Sitecore. For our example this means modifying the “languages” parameter:

<agent type="Sitecore.Tasks.PublishAgent" method="Run" interval="00:01:00">

<param desc="source database">master</param>

<param desc="target database">web</param>

<param desc="mode (full or incremental)">incremental</param>

**<param desc="languages">en</param>**
</agent>