Marius Gedminas a écrit :
On Fri, Jun 13, 2008 at 09:40:06PM +0200, Christophe Combelles wrote:
While fixing some bugs in,
I've also modified the implementation of the BTreeContainer,
by not inheriting from the SampleContainer, and directly accessing the btree. This had remained as a TODO in the file, so I did it, but...

The result is all previous persisted BTreeContainers (such as PrincipalFolder) are broken because the btree used to be stored in self._SampleContainer__data, while the new implementation stores it in self._BTreeContainer__data.

So I've added a property to offer a transparent backward compatibility:

    def _get__data(self):
            return self._BTreeContainer__data

Please do not use bare except clauses.  Replace this with

          except AttributeError:

            return self._SampleContainer__data
    def _set__data(self, value):
            self._BTreeContainer__data = value

When could this ever fail?

            self._SampleContainer__data = value
    def _del_data(self):
            del self._BTreeContainer__data
            del self._SampleContainer__data

Do we need __del__ at all?

    __data = property(_get__data, _set__data, _del_data)

Do you think it is safe?

Not if you want compatibility in both directions.  If you want databases
created with the new to be readable with the old (consider, e.g. a developer using a sandbox and
switching between bleeding-edge development and old maintenance
branches), then you can't do this.

Is there any better solution for this?

Perhaps a __setstate__ method to rename the attribute?  See the
PersistentMapping class in persistent/ for an example.

Should I rather write an evolution script?


Or should I revert all this back to inheriting from SampleContainer?

Or you could do like Benji York suggested and always use the
backwards-compatible name _SampleContainer__data.

thanks for the suggestions! I will do what Benji told, this seems the safest solution, and will allow to backport it to the 3.5 branch, so that the btree length calculation could also be fixed in zope 3.4.


(Why oh why did SampleContainer want to use a double underscored name?)

Marius Gedminas


Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Zope-Dev maillist  -
**  No cross posts or HTML encoding!  **
(Related lists - )

Reply via email to