Removing a piece of code from Add-on

I have a piece of code that I want to remove from my add-on for a Plone 4.3.15 site.

However, I have problems with that, the site simply stops working.

Here is the code:

...
class ISizeValuePair(Interface):
    name = schema.TextLine(title=u"Nome", required=True)
    largura = schema.Int(title=u"Largura", required=True)
    altura = schema.Int(title=u"Altura",required=True)


class PersistentObject(PersistentField, schema.Object):
    pass


class ISizeSettings(Interface):

    tamanhos = schema.Tuple(
        title=u'Tamanhos',
        value_type=PersistentObject(ISizeValuePair,title=u"Tamanhos"),
        required=False,
        default=(),
        missing_value=(),
    )

class SizeValuePair(object):
    implements(ISizeValuePair)

registerFactoryAdapter(ISizeValuePair, SizeValuePair)

I also register ISizeSettings in registry.xml, like this:

<?xml version="1.0"?>
<registry>
    <records interface="ufal.profile.interfaces.ISizeSettings" />
</registry>

When I remove this code the following error is returned:

2018-11-12 09:20:47 ERROR ZODB.Connection Couldn't load state for 0x3f58
Traceback (most recent call last):
  File "/home/alexandre/dev/plone4/eggs/ZODB3-3.10.7-py2.7-linux-x86_64.egg/ZODB/Connection.py", line 860, in setstate
    self._setstate(obj)
  File "/home/alexandre/dev/plone4/eggs/ZODB3-3.10.7-py2.7-linux-x86_64.egg/ZODB/Connection.py", line 914, in _setstate
    self._reader.setGhostState(obj, p)
  File "/home/alexandre/dev/plone4/eggs/ZODB3-3.10.7-py2.7-linux-x86_64.egg/ZODB/serialize.py", line 612, in setGhostState
    state = self.getState(pickle)
  File "/home/alexandre/dev/plone4/eggs/ZODB3-3.10.7-py2.7-linux-x86_64.egg/ZODB/serialize.py", line 605, in getState
    return unpickler.load()
  File "/usr/lib/python2.7/copy_reg.py", line 48, in _reconstructor
    obj = object.__new__(cls)
TypeError: object.__new__(SizeValuePair) is not safe, use Persistence.Persistent.__new__()

I've already tried using wildcard.fixpersistentutilities and the instructions on this page to remove this problem, but I was not successful.

Does anyone know what the correct way to solve this problem?

I know the above TypeError from cases where a formerly persistent object (stored in the ZODB) became non-persistent (after a change) or vice versa.
The correct way to handle such a case is to remove those objects from the ZODB before you change your code.

Your error message refers to SizeValuePair. Thus, I assume that the problematic object (in the ZODB) has this class. Your code does not give a hint where such an object could be. Likely, it is also a good idea to remove the ISizeSettings records from the registry before your code change.

After removing the records from the registry, the site worked again.
I should have tried this first! :sweat_smile:

Thanks