[Twisted-Python] Re: assignKeyAttr in row object
Tsai Li Ming
mailinglist at ltsai.com
Tue Oct 5 11:54:41 EDT 2004
Tsai Li Ming wrote:
> Dave Peticolas wrote:
>
>> On Tue, 2004-10-05 at 05:15, Tsai Li Ming wrote:
>>
>>> Dear all,
>>>
>>> What is the assignKeyAttr method used for in a row object? Is it
>>> similar to a primary key that can be used to identity the instance?
>>
>>
>>
>> Yes, assignKeyAttr is used to change the primary key of a row object.
>>
>> dave
>
>
> Hi Dave,
>
> Is it necessary to use assignKeyAttr? From the source code, it doesn't
> seem to do anything special, except to change the primary key(s)?
>
> def assignKeyAttr(self, attrName, value):
> """Assign to a key attribute.
>
> This cannot be done through normal means to protect changing
> keys of db objects.
> """
> found = 0
> for keyColumn, type in self.rowKeyColumns:
> if keyColumn == attrName:
> found = 1
> if not found:
> raise DBError("%s is not a key columns." % attrName)
> self.__dict__[attrName] = value
>
> Alternatively, I could set the primary key manually.
> newRoom = RoomRow()
> newRoom.roomID = get_unique _id()
> #newRoom.assignKeyAttr("roomID", get_unique _id())
> reflector.insertRow(newRoom).addCallback(onInsert)
>
> Liming
My mistake. Twisted has the __setattr__ defined so that key values must
be changed via assignKeyAttr.
Liming
More information about the Twisted-Python
mailing list