[ZODB-Dev] ZODB Object evolution and class variables ?

Casey Duncan casey@zope.com
Mon, 4 Nov 2002 17:32:58 -0500


As you have found, changes to the class are not persisted. Here are some=20
options:

1. Don't use an incremental count, use a random number or a timestamp val=
ue or=20
some combination of both.

2. If it must be incremental, do it by iterating over the ids of the cont=
ainer=20
it is being added to. This may mean that multiple objects could exist wit=
h=20
the same id (but in different folders).

3. Use a separate persistent object to store the count. Something like a=20
BTrees.Length.Length which automatically handles write conflicts. Store t=
his=20
object in the root with a fixed id. It could even be shared by multiple=20
classes.

-Casey

On Monday 04 November 2002 04:54 pm, Andreas Martin wrote:
> Hallo !
>=20
> I'm a Zopenewbie and just experimenting with own Zope Python products
> and I don't know whether this is the rigt place to post my question.=20
>=20
> I created a sample News Product that should automatically set the id of
> a new instance to an autogenerated number.
>=20
> The class looks like this:
>=20
> class News(SimpleItem):
>     "A News object"
>=20
>     meta_type =3D "News"
>=20
>     actualKey =3D 0
>=20
>     def __init__(self, teaser):
>         self.key          =3D News.actualKey
>         News.actualKey   +=3D 1
>         self.id           =3D str(self.key)
>         self.teaser       =3D teaser
>=20
> That's ok but when I change the class definition I have the problem tha=
t
> my class variable "actualkey" starts again by 0.
>=20
> I managed to add new instance attributes like "teaser" and a
> __setstate__ function is working fine.
>=20
> My only problem is the global class variable, that is changed to 0 when
> I refresh my product in the zope management interface.
>=20
> Thanks for help
>=20
>=20
>=20
> _______________________________________________
> For more information about ZODB, see the ZODB Wiki:
> http://www.zope.org/Wikis/ZODB/
>=20
> ZODB-Dev mailing list  -  ZODB-Dev@zope.org
> http://lists.zope.org/mailman/listinfo/zodb-dev
>=20