[PEAK] More trouble with my relation
Phillip J. Eby
pje at telecommunity.com
Thu Oct 21 12:58:14 EDT 2004
At 12:25 PM 10/21/04 -0400, R. David Murray wrote:
> File "/usr/local/lib/python2.4/site-packages/peak/model/features.py",
> line 505, in _notifyUnlink
> otherEnd = getattr(item.__class__, refEnd)
>AttributeError: type object 'NoneType' has no attribute 'subaccounts'
>-------------------------------------------------
>
>None is what I return as the state for the masteraccount attribute
>in my DM if the account has no master account. Is there something
>besides None I should be returning as the "not set" state?
Yes, use the "not set" state, i.e., don't put in a value for that key.
> I know
>it's the masteraccount field involved because I tried using ''
>instead of None as the "not set" value and got the same error for
>trying to access subaccounts on a string. But I don't know why
>it's even accessing the masteraccount field, which is why I think
>I must be doing something stupid.
If you had a valid master account already present, it would need to unlink
the reverse link, from the subaccounts field. So, the issue here is that
you shouldn't use 'None' as the value for a field that's a bidirectional
link. Note that this is different from having the field's 'defaultValue'
set to None. 'defaultValue' is what gets returned when the attribute *has
no value*. When dealing with the object's internal state (in a DM), you
must reflect the internal state, not the object's API.
>Also, what "not set" value should I use for the Collection field?
You can use an empty list, but it might be better to just not include it.
In the general case for a relational mapping, however, you would use a
QueryLink and not bother with whether it's empty or not. See 'peak help
storage.QueryLink' for more details.
More information about the PEAK
mailing list