[Dev] Small tweak to parcel loader
Morgen Sagen
morgen at osafoundation.org
Fri Jun 11 18:36:41 PDT 2004
On Jun 11, 2004, at 1:05 PM, John Anderson wrote:
> Suppose I have two attributes:
>
> <Attribute itemName="parentBlock">
> <type itemref="docSchema:Block"/>
> <cardinality>single</cardinality>
> <inverseAttribute itemref="docSchema:Block/childrenBlocks"/>
> <defaultValue itemref="None"/>
> </Attribute>
> <Attribute itemName="childrenBlocks">
> <type itemref="docSchema:Block"/>
> <cardinality>list</cardinality>
> <inverseAttribute itemref="docSchema:Block/parentBlock"/>
> <initialValue/>
> </Attribute>
>
> I would assume that block.parent block would never throw an
> AttributeNotFound exception. However, in my code it does. Is this a
> bug or is the data model too complicated for me to understand?
>
> John
Hmm, I just added a minimal parcel in the unit tests which has two
attributes similar to what you have, and when I test it, parentBlock is
being set to None. You can see the XML here:
http://cvs.osafoundation.org/viewcvs.cgi/chandler/repository/parcel/
tests/testparcels/collections/parcel.xml?rev=HEAD&content-type=text/
vnd.viewcvs-markup
However, if I create three items, parent, child1 and child2, and do:
child1.parentBlock = parent
child2.parentBlock = parent
for child in parent.childrenBlocks:
print child, child.parentBlock
...I get an exception:
Traceback (most recent call last):
File "TestCollections.py", line 35, in testCollections
for child in parent.childrenBlocks:
File "/Users/morgen/dev/chandler/repository/util/LinkedMap.py", line
238, in __iter__
yield self[key]
File "/Users/morgen/dev/chandler/repository/item/ItemRef.py", line
528, in __getitem__
return self._getRef(key).other(self._getItem())
File "/Users/morgen/dev/chandler/repository/item/ItemRef.py", line
126, in other
raise ValueError, "%s doesn't reference %s" %(self, item)
ValueError: <ItemRef: <Item: child1
49783b2a-bc10-11d8-a380-000a95bb2738> - <Item: parent
4976fb48-bc10-11d8-a380-000a95bb2738>> doesn't reference <Kind: Block
4970bd8c-bc10-11d8-a380-000a95bb2738>
I suspect that this has something to do with the way the parcel loader
is calling the repo API to set the initialValue of the childrenBlocks
attribute to an empty list:
attributeItem.addValue("initialValue", [ ] )
Perhaps Andi can set me straight as to the proper way to use the API to
specify an initialValue of empty list (or dict).
~morgen
> Morgen Sagen wrote:
>
>> By popular demand: if you want to set the defaultValue or
>> initialValue of a list or dict attribute to be an empty list or dict,
>> you may now include either "<defaultValue/>" or "<initialValue/>"
>> inside that attribute's definition. For example:
>>
>> <Attribute itemName="listAttr">
>> <displayName>List Attribute</displayName>
>> <cardinality>list</cardinality>
>> <type itemref="String"/>
>> <initialValue/>
>> </Attribute>
>>
>> ~morgen
>>
>> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>>
>> Open Source Applications Foundation "Dev" mailing list
>> http://lists.osafoundation.org/mailman/listinfo/dev
>
> _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _
>
> Open Source Applications Foundation "Dev" mailing list
> http://lists.osafoundation.org/mailman/listinfo/dev
More information about the Dev
mailing list