In an environment I manage I recently encountered an MS bug in some site generation code.
Case: Sharepoint list form with site metadata. When the record gets approved a site is automatically generated, with unique permissions based on data from the list.
Bug: The site is created but the Visitor group property isn't saved. By default CreateDefaultAssociatedGroups will not create the Visitor group, but instead associate the Site Collection Visitor group with the new site's AssociatedVisitorGroup property. To get around this you need to set this property to null before you call CreateDefaultAssociatedGroups
eg:
oNewSite.AssociatedVisitorGroup = null;
oNewSite.BreakRoleInheritance(false);
oNewSite.Update();
oNewSite.CreateDefaultAssociatedGroups(oOwner.LoginName, oOwner.LoginName, sNewSite);
oNewSite.Update();
But, and here's the bug; while this does create the groups and the proper association, the site property vti_associatevisitorgroup is not updated. What happens now is that even if you update the Site Groups through the UI it still won't update this property and there will never be a Visitor group association.
Fix: Fortunately the fix is easy; just update the property with the created visitor group id.
oNewSite.CreateDefaultAssociatedGroups(oOwner.LoginName, oOwner.LoginName, sNewSite);
oNewSite.Properties["vti_associatevisitorgroup"] = oNewSite.AssociatedVisitorGroup.ID.ToString();
oNewSite.Properties.Update();
oNewSite.Update();