Skip to main content

improved ZODB persistence

Project description


This package provides a base class for persistent objects with the advantage that the object is only marked as changed if an attribute has really changed.

>>> import transaction
>>> from ZODB.tests.util import DB
>>> from lovely import persistent
>>> p = LovelyPersistent()
>>> p._p_changed
>>> p.a = 1
>>> db = DB()
>>> conn =
>>> conn.root()['p'] = p
>>> transaction.commit()

After commiting the changes the object is no longer in changed state.

>>> p._p_changed

Setting a with its existing value doesn’t put the object in cahnged state.

>>> p.a
>>> p.a = 1
>>> p._p_changed

But modifying a :

>>> p.a = 2
>>> p._p_changed
>>> transaction.commit()
>>> p._p_changed

Deleting an attribute also put the object into changed state.

>>> del p.a
>>> p._p_changed

Special Properties

Special property implementations do work too. To show this we use the fieldproperties from zope.schema.

>>> from zope.schema.fieldproperty import FieldProperty
>>> from zope import schema, interface
>>> class IMyFace(interface.Interface):
...     eyesOpen = schema.Bool(default=True, required=False)
>>> class MyFace(persistent.Persistent):
...     eyesOpen = FieldProperty(IMyFace['eyesOpen'])
>>> persistent.tests.MyFace = MyFace
>>> MyFace.__module__ = persistent.tests.setUp.__module__
>>> myFace = conn.root()['myFace'] = MyFace()
>>> transaction.commit()

Default values.

>>> myFace.eyesOpen


>>> myFace.eyesOpen = 'not always'
Traceback (most recent call last):
WrongType: ('not always', <type 'bool'>)

Note, setting to default value does not change the object.

>>> transaction.commit()
>>> myFace.eyesOpen = True
>>> myFace._p_changed
>>> transaction.commit()
>>> myFace.eyesOpen = False
>>> myFace._p_changed

Changes in lovely.persistent

2007/12/10 0.1.1

  • moved to

2007/06/19 0.1.0a1

  • added zodb to dependencies
  • added support for fieldproperties


Project details

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for lovely.persistent, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size lovely.persistent-0.1.1-py2.4.egg (9.5 kB) File type Egg Python version 2.4 Upload date Hashes View
Filename, size lovely.persistent-0.1.1.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page