[Twisted-Python] enterprise.row

Dave Peticolas dave at krondo.com
Sun Apr 6 04:49:06 EDT 2003


On Sat, 2003-04-05 at 12:20, Justin Ryan wrote:
> "ZONE_SOAID" is the primary key for the "ZONE_SOA" table.  I did not set
> the primary key because it is a postgres serial column - that is, it
> should automatically increment the pkey each time a new row is
> inserted.  If I use setKeyAttr("ZONE_SOAID", 1), the AttributeError
> comes up for the next attribute that is not being given a value.
> 
> I read the row documentation a little more, and it doesn't appear to
> like what I'm trying to do all too much.  I can use python to fill the
> object with default values, but the database will do that for me, and
> with less work on the part of my application (plus, the KeyFactory class
> says it is not thread-safe, I know that my postgres series is).

I think your diagnosis is correct. The current t.e code does not handle
default values in the database schema, afaik. Given that, and the fact
that the reflector wants to cache rows by primary keys, it can't support
leaving primary keys unset before you create a new row.


> Is there any way for row to allow me to insert a new row with some empty
> values, and simply ignore them (allowing the database to use its'
> default)?  If not, any idears on where/how this might need to be done? 
> Perhaps this is a good time for me to foray into twisted hacking..

What I have done with postgres is to generate the primay key using
the nextval function on the sequence used for the serial column, setting
the row object's primary key, and then inserting it. This makes the t.e
code happy and you often need to know the new key anyway.

It would be nice to make t.e allow for default values and db-generated
primary keys, but that code would almost certainly need to be 
per-database since different databases handle serial/autoincrement
columns differently.

dave

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: This is a digitally signed message part
Url : http://twistedmatrix.com/pipermail/twisted-python/attachments/20030406/f78f2a53/attachment.pgp 


More information about the Twisted-Python mailing list