ZODB, maintaining referential integrity

41 views
Skip to first unread message

Joe Steeve

unread,
Apr 21, 2016, 3:37:07 AM4/21/16
to Pylons Discuss
How to maintain "referential integrity" in a ZODB. Simply put: When an
object-A is removed from a container, the references to object-A, in
other objects should go invalid.

I tried holding a persistent.WeakRef whenever a reference was required.
However, the WeakRef seems to go invalid only after a GC on the db
(correct me if I am wrong).

The other approach seems to be to use IObjectWillBeRemovedEvent at the
site of the referencing object, to act accordingly.

How do other people deal with this?

--
Joe Steeve
HiPro IT Solutions Private Limited
http://hipro.co.in/
signature.asc

Thierry Florac

unread,
Apr 21, 2016, 5:09:51 AM4/21/16
to pylons-...@googlegroups.com
Hi,

Actually I handle this use case using IObjectRemovedEvent subscribers.
Can't see any other simple way...  :-/

Best regards,
Thierry


--
You received this message because you are subscribed to the Google Groups "pylons-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to pylons-discus...@googlegroups.com.
To post to this group, send email to pylons-...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/pylons-discuss/1461224218.20052.19.camel%40hipro.co.in.
For more options, visit https://groups.google.com/d/optout.



--

Chris Rossi

unread,
Apr 21, 2016, 10:11:44 AM4/21/16
to pylons-...@googlegroups.com
The other approach would be to only store objects in one canonical place, and use references that just store the path to the object or the oid.

Chris

Thierry Florac

unread,
Apr 21, 2016, 10:50:28 AM4/21/16
to pylons-...@googlegroups.com
Hi !

I often use internal IDs (via an IIntIds utility) to store objects references.
The drawback of this method is that you have an indirection and you always have to check that the reference target is still available before using it!
So even in this use case I use an event listener to remove the reference when the target is removed...

Best regards,
Thierry


For more options, visit https://groups.google.com/d/optout.

Joe Steeve

unread,
May 2, 2016, 7:52:16 AM5/2/16
to pylons-...@googlegroups.com
On Thu, 2016-04-21 at 11:09 +0200, Thierry Florac wrote:
> Actually I handle this use case using IObjectRemovedEvent subscribers.
> Can't see any other simple way... :-/

I am taking this approach. Specifically I am using repoze.folder's
IObjectWillBeRemoved. Thanks :)
signature.asc
Reply all
Reply to author
Forward
0 new messages