Ha, human error!

The corrected Events:

class Event(sqlobject):
 WorldTakeOverId = ForeignKey('WorldTakeOver',cascade=False)
 EventDate = DateCol(default= datetime.now())
 EventTypeId = ForeignKey("EventType",cascade=False)
 Description = UnicodeCol(default=None)
 def _init(self,*args,**kwargs):
   """
   When we create an Event, we have to update the WorldTakeOver object
   so it knows the LastEventDate and its current status, if any.
   """
   >>> SQLObject._init(self, *args, **kwargs) <<<
   wto = WorldTakeOver.get(self.WorldTakeOverId)
   wto.LastEventDate = self.EventDate
   if self.debug: print "New event. Status:", self.Type.Status
   if self.Type.Status:
     opt.CurrentStatus = self.Type.Status
     if self.debug: print "Updated WorldTakeOver status:",wto.CurrentStatus

However, I'm still fascinated that this didn't cause any problems when we
add rows to the table, only when we try to read them.

Molly

On 5/22/07, Molly Aplet <[EMAIL PROTECTED]> wrote:

I've got two classes (which I'm simplifying here for the sake of an easier
demonstration).

class WorldTakeOver(sqlobject):
  Events = MultipleJoin('Event',joinColumn="OptimizationId")
  LastEventDate = DateTimeCol(default=None)
  CurrentStatus = UnicodeCol(default=None)
  Notes = UnicodeCol(default=None)
  def AddEvent(self,event_name,desc=None):
    et = EventType.byName(event_name)
    e = Event(OptimizationId= self.id,EventTypeId=et.id,Description=desc)

class Event(sqlobject):
  WorldTakeOverId = ForeignKey(WorldTakeOver',cascade=False)
  EventDate = DateCol(default= datetime.now())
  EventTypeId = ForeignKey("EventType",cascade=False)
  Description = UnicodeCol(default=None)
  def _init(self,*args,**kwargs):
    """
    When we create an Event, we have to update the WorldTakeOver object
    so it knows the LastEventDate and its current status, if any.
    """
    wto = WorldTakeOver.get(self.WorldTakeOverId)
    wto.LastEventDate = self.EventDate
    if self.debug: print "New event. Status:", self.Type.Status
    if self.Type.Status:
      opt.CurrentStatus = self.Type.Status
      if self.debug: print "Updated WorldTakeOver status:",
wto.CurrentStatus


I'm having trouble accessing my Event objects. What's strange is that
there are no issues with creating events in the first place. However, both
(for example)

w = WorldTakeOver.get(123)
w.Events

and

e = Event.get(123)

throw the same error:

  File "<stdin>", line 1, in ?
  File "/usr/local/lib/python2.4/site-packages/SQLObject- 
0.7.4-py2.4.egg/sqlobject/main.py",
line 920, in get
    val._init(id, connection, selectResults)
  File "WorldTakeOver.py", line 253, in _init
    wto = WorldTakeOver.get(self.WorldTakeOverId)
  File "<string>", line 1, in <lambda>
  File 
"/usr/local/lib/python2.4/site-packages/SQLObject-0.7.4-py2.4.egg/sqlobject/main.py",
line 997, in _SO_loadValue
    self._SO_writeLock.release()
AttributeError: 'Event' object has no attribute '_SO_writeLock'

I'm not using any locks on these objects at all, so I'm not sure why I'm
encountering a writeLock when I try to read the object but not when I write
it. Is there anything I'm overlooking here?

Thanks,
Molly

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
sqlobject-discuss mailing list
sqlobject-discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to