[PEAK] Need help interpreting traceback

R. David Murray rdmurray at bitdance.com
Wed Oct 20 16:11:09 EDT 2004


On Wed, 20 Oct 2004, R. David Murray wrote:
> > At 01:19 PM 10/20/04 -0400, R. David Murray wrote:
> > I'm confused.  Why does your 'AccountDM' try to obtain itself?
>
> Yes, it does.  The Account objects can refer to each other in a
> parent/child tree.  Is there a "best practices" way of doing this?
> Currently I've tried sticking 'Account' in the referencedType field
> of the domain model, but I'm not really clear on how string values
> work there, so I won't be surprised if this causes me issues later.

I was right.  As soon as I tried to set the parent/child attributes
I got an error.  I've googled and read, and it still seems to me
that 'Account' should be the correct value.  Here's my model, with
all non-relevant fields cut out.

---------------------------------------
from datetime import datetime
from peak.api import *

class Account(model.Element):

    class acctnum(model.Attribute):
        referencedType = model.String
        defaultValue = ''

    class subaccounts(model.Collection):
        referencedType = 'Account'
        defaultValue = []
        referencedEnd = 'masteraccount'

    class masteraccount(model.Attribute):
        referencedType = 'Account'
        defaultValue = ''
        referencedEnd = 'subaccounts'

    def __str__(self): return self.acctnum
-----------------------------------------

The acctnum field is my oid, for whatever
that is worth.

When I try to set the masteraccount field
on an account, I get the following traceback:

-----------------------------------------
Traceback (most recent call last):
  File "/usr/local/bin/peak", line 4, in ?
    commands.runMain( commands.Bootstrap )
  File "/usr/local/lib/python2.4/site-packages/peak/running/commands.py", line 70, in runMain
    result = factory().run()
  File "/usr/local/lib/python2.4/site-packages/peak/running/commands.py", line 211, in run
    return self._run() or 0
  File "/home/rdmurray/proj/fcgbilling/commands.py", line 112, in _run
    self.Accounts[n].masteraccount = master
  File "/usr/local/lib/python2.4/site-packages/peak/model/features.py", line 79, in __set__
    self.set(ob,val)
  File "/usr/local/lib/python2.4/site-packages/peak/model/features.py", line 348, in set
    feature._notifyLink(element,val)
  File "/usr/local/lib/python2.4/site-packages/peak/model/features.py", line 464, in _notifyLink
    otherEnd = getattr(item.__class__, refEnd)
AttributeError: type object 'str' has no attribute 'subaccounts'
-----------------------------------------

It *looks* like it isn't trying to resolve Account?  If I change
the string to something like 'fcgbilling/model/account', though, I
get a name lookup error.  So I'm confused.  Is having a self-referencing
Element not supported, or am I missing some info? (Or doing something
stupid!)

--David



More information about the PEAK mailing list