Re: [Zope] Class instances changing address?
At Friday 20/1/2006 20:07, Jeff Gentry wrote:
As background, the primary class (A) maintains a handle to an instance of another class (B) which handles interaction w/ a psycopg db controller. Class A also will instantiate several instances of Class C and as part of the construction will pass it the handle to class B. So in summary, A has a B and has 1:n C's, and C has a reference to B. A & B have physical representations in the ZMI, while instances of C are 'virtual'.
If you follow these rules you should be safe: - Never store a reference to a persistent object inside another persistent object; use its id or path to retrieve it when needed. - Never store a reference to a persistent object inside a non-persistent object. - If a persistent object "owns" some other persistent objects, make the first an ObjectManager. - Let Zope manage transactions, and avoid bare try/excepts Of course you can break the rules if you really really know what you are doing but they are a good starting point. And reading about how persistence works is a big help (it appears you've already read it, I think). Gabriel Genellina Softlab SRL
Gabriel Genellina wrote:
- Never store a reference to a persistent object inside another persistent object; use its id or path to retrieve it when needed.
I suspect storing the aq_base of an object will mitigate any problems you have here...
- Never store a reference to a persistent object inside a non-persistent object.
I don't think this is a useful warning.
- If a persistent object "owns" some other persistent objects, make the first an ObjectManager.
...and this is bordering on rubbish ;-)
- Let Zope manage transactions, and avoid bare try/excepts
Aha, now this is a good one :-) cheers, Chris -- Simplistix - Content Management, Zope & Python Consulting - http://www.simplistix.co.uk
On 1/23/06, Chris Withers <chris@simplistix.co.uk> wrote:
- Never store a reference to a persistent object inside a non-persistent object.
I don't think this is a useful warning.
Unless you expect to retrieve it after a server restart. ;) -- Lennart Regebro, Nuxeo http://www.nuxeo.com/ CPS Content Management http://www.cps-project.org/
participants (3)
-
Chris Withers -
Gabriel Genellina -
Lennart Regebro