[Modeling-cvs] ProjectModeling/Modeling CHANGES,1.141,1.142 CustomObject.py,1.17,1.18
Status: Abandoned
Brought to you by:
sbigaret
|
From: <sbi...@us...> - 2003-08-02 11:15:00
|
Update of /cvsroot/modeling/ProjectModeling/Modeling
In directory sc8-pr-cvs1:/tmp/cvs-serv32454
Modified Files:
CHANGES CustomObject.py
Log Message:
Fixed bug #774989: improper result returned by CustomObject.snapshot() wrt
tomany relationships --see CustomObject.snapshot() documentation for details.
Index: CHANGES
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/CHANGES,v
retrieving revision 1.141
retrieving revision 1.142
diff -C2 -d -r1.141 -r1.142
*** CHANGES 2 Aug 2003 09:40:49 -0000 1.141
--- CHANGES 2 Aug 2003 11:14:57 -0000 1.142
***************
*** 8,11 ****
--- 8,15 ----
--------------------------------------------------------
+ * Fixed bug #774989: improper result returned by CustomObject.snapshot()
+ wrt tomany relationships --see CustomObject.snapshot() documentation for
+ details.
+
* Fixed bug #779775, on behalf of Yannick Gingras who reported the bug and
gave the patch fixing it.
Index: CustomObject.py
===================================================================
RCS file: /cvsroot/modeling/ProjectModeling/Modeling/CustomObject.py,v
retrieving revision 1.17
retrieving revision 1.18
diff -C2 -d -r1.17 -r1.18
*** CustomObject.py 29 Jul 2003 18:42:13 -0000 1.17
--- CustomObject.py 2 Aug 2003 11:14:57 -0000 1.18
***************
*** 40,44 ****
import Validation
from RelationshipManipulation import RelationshipManipulation
! from FaultHandler import FaultHandler
import ObserverCenter
from EditingContext import ObjectNotRegisteredError
--- 40,44 ----
import Validation
from RelationshipManipulation import RelationshipManipulation
! from FaultHandler import FaultHandler, AccessArrayFaultHandler
import ObserverCenter
from EditingContext import ObjectNotRegisteredError
***************
*** 49,52 ****
--- 49,94 ----
+ class Snapshot_ToManyFault:
+ """
+ Snapshot_ToManyFault is used in CustomObject.snapshot(), when returning
+ the value for a to-many relationship which is still a fault.
+
+ It should not be mistaken for FaultHandler.AccessArrayFaultHandler, which
+ holds the real to-many fault. An instance of this class is just a mean for
+ CustomObject.snapshot() to tell that it found a fault. If you need the real
+ to-many fault, use getToManyFault().
+
+ See also: CustomObject.snapshot() for additional details.
+ """
+ def __init__(self, sourceGlobalID, key):
+ """Initializer
+
+ Parameter:
+
+ sourceGlobalID -- a non temporary GlobalID (this is a non sense to have
+ a to many fault for an object that has just been inserted
+
+ key -- the corresponding to-many relationship's name
+
+ Raises ValueError is sourceGlobalID.isTemporary() is true.
+
+ """
+ if sourceGlobalID.isTemporary():
+ raise ValueError, 'sourceGlobalID cannot be a temporary global id'
+ self.sourceGlobalID=sourceGlobalID
+ self.key=key
+
+ def getToManyFault(self, ec):
+ """
+ Returns the real to-many fault that this object represents.
+
+ Parameter:
+
+ ec -- an EditingContext
+
+ """
+ return ec.arrayFaultWithSourceGlobalID(self.sourceGlobalID, self.key,
+ ec)
+
class CustomObject(RelationshipManipulation, DatabaseObject):
"""
***************
*** 236,245 ****
are allPropertyKeys(), and whose values are :
! - for attribute, the corresponding value
! - for toOne relationships, the GlobalID of the related object (or None)
! - for toMany relationships: GlobalIDs of related objects, or None if the
! corresponding value is a toMany fault.
Raises ObjectNotRegisteredError if the object itself is not registered in
--- 278,310 ----
are allPropertyKeys(), and whose values are :
! - for attribute, the corresponding value,
! - for toOne relationships, the GlobalID of the related object (or None).
! If you want to get the real object corresponding to that global id,
! simply call EditingContext.faultForGlobalID() on
! self.editingContext().
! - For toMany relationships, the returned value depends on whether the
! set of related objects is still a fault or not:
!
! - if it is still a to-many fault, you'll get an instance of
! Snapshot_ToManyFault. To get the real to-many fault (instance of
! FaultHandler.AccessArrayFaultHandler), simply call
! getToManyFault() on this instance,
!
! - otherwise, you get the list of the GlobalIDs of the related
! objects
!
! Why are to-many faults handled this way? We do not want snapshot() to
! trigger any round-trip to the database. One could say, okay, but then
! you could return the to-many fault as well. True, but this won't be
! consistent with the other values returned by snapshot: values for
! to-one relationship are globalIDs with which you must explicitely call
! ec.faultForGlobalID() to get the real object. Same for to-many faults:
! you also need to explicitely call Snapshot_ToManyFault's
! getToManyFault() to get the whole (faulted) array. Last, this also
! prevents a to-many fault to be cleared by mistake (because simply
! looking at one of the fault properties, such as itys length, triggers
! a round-trip to the database).
Raises ObjectNotRegisteredError if the object itself is not registered in
***************
*** 284,288 ****
else:
! res[key]=None
else:
--- 349,353 ----
else:
! res[key]=Snapshot_ToManyFault(self.globalID(), key)
else:
***************
*** 334,338 ****
ec=self.editingContext()
if ec is None:
! raise ObjectNotRegisteredError, 'Unable to compute snapshot_raw: no editingContext()'
if self.isFault():
self.willRead()
--- 399,403 ----
ec=self.editingContext()
if ec is None:
! raise ObjectNotRegisteredError, 'Unable to compute snapshot_raw: the object is not registered in an EditingContext'
if self.isFault():
self.willRead()
***************
*** 447,455 ****
elif key in toManyKeys:
! if value is not None:
! value=map(lambda gID, ec=ec: ec.faultForGlobalID(gID, ec), value)
else:
! gID=ec.globalIDForObject(self)
! value=ec.arrayFaultWithSourceGlobalID(gID, key, ec)
self.takeStoredValueForKey(value, key)
--- 512,524 ----
elif key in toManyKeys:
! if isinstance(value, Snapshot_ToManyFault):
! #gID=ec.globalIDForObject(self)
! #value=ec.arrayFaultWithSourceGlobalID(gID, key, ec)
! value=value.getToManyFault(ec)
else:
! try:
! value=map(lambda gID, ec=ec: ec.faultForGlobalID(gID, ec), value)
! except:
! import pdb ; pdb.set_trace()
self.takeStoredValueForKey(value, key)
|