CRM-1594 we added the ability to make custom fields view-only so as to be modified by PHP only. This works fine if you are altering the field during a form hook (I think). But it doesn't work if you attempt to alter the field via the API. The problem is a little chunk of code in CRM/Core/BAO/CustomField.php line 1232:
// return if field is a 'code' field
if ( CRM_Utils_Array::value( 'is_view', $customFields[$customFieldId] ) )
This was added in r1482 as part of
If I remove this chunk it all works out fine, but I'm unsure if there's any other repercussions to this change. The field isn't shown on the main contact edit form, so it appears safe to me.