[Zope3-Users] adding indexes in a __init__ method

Darryl Cousins darryl at darrylcousins.net.nz
Tue Jul 25 07:09:29 EDT 2006


Hi All,

I was thinking about that del(self.field) that I threw in. Wouldn't that
remove the object too and therefore the key reference?

Apparently not (in the test anyway)::

    >>> class TestField(Persistent):
    ...     id = u''
    ...     def __init__(self, id):
    ...          self.id = id

    >>> class TestCaseTwo(Persistent):
    ...     def __init__(self):
    ...         self.field = TestField(id=u'test case two')
    ...     def initfield(self):
    ...         self.fieldkey = KeyReferenceToPersistent(self.field)
    ...         del(self.field)

    >>> t = TestCaseTwo()
    >>> tc = root['t'] = t
    >>> transaction.commit()
    >>> tc.initfield()
    >>> print tc.field
    Traceback (most recent call last):
    ...
    AttributeError:...
    >>> print tc.fieldkey().id
    test case two

    >>> transaction.commit()
    >>> print tc.fieldkey().id  # I thought this would fail
    test case two

Best regards,
Darryl



More information about the Zope3-users mailing list