If you have specific broken portlets that needs to be removed from your Plone site, you will have to reinstall the product that contains your portlets, otherwise you will get this error :

Traceback (innermost last):
Module ZPublisher.Publish, line 126, in publish
Module ZPublisher.mapply, line 77, in mapply
Module ZPublisher.Publish, line 46, in call_object
Module plone.app.portlets.browser.kss, line 66, in delete_portlet
Module zope.container.ordered, line 243, in __delitem__
Module zope.container.contained, line 647, in uncontained
Module OFS.Uninstalled, line 45, in __getattr__
AttributeError: __parent__

But what if you just can’t find / reinstall the product ?

You could already remove the broken portlet through Plone UI, thanks to packages like collective.braveportletsmanager. Now you will be able to do it without any additional package thanks to this change in plone.app.portlet.

If you want to delete broken portlets programmatically, this is possible by disabling the error raised before your usual portlet removal function (see fixing_up in zope.container.contained) :

from zope.container import contained
contained.fixing_up = True
manager = getUtility(IPortletManager, name=u'plone.leftcolumn', context=portal)
assignments = getMultiAdapter((portal, manager), IPortletAssignmentMapping)
for portlet in assignments:
    del assignments[portlet]
contained.fixing_up = False

We used this in a migration step for a customer.
Enjoy !