On Sep 22, 2010, at 5:17 PM, Michael Hipp wrote:

> On 9/22/2010 11:21 AM, Michael Hipp wrote:
> 
>>  new = Car()
>>  new.id_ = old.id_
>>  new = sess.merge(new)
>>  new.auction = old.auction # do this *after* merge
>>  sess.commit()
>> 
>> This seems to work and  ...
> 
> Bah. I spoke too soon - it just doesn't throw an exception.

that absolutely does what you tell it (guess thats not what you want).  Make 
sure Car's init is:

    def __init__(self, lane=None, make='', auction=None):
        self.lane = lane
        self.make = make
        if auction is not None:
            self.auction = auction

then:

new = Car()
new.id_ = old.id_
new.lane = old.lane
new = sess.merge(new)
new.auction = old.auction
sess.commit()

SQL:

UPDATE cars SET make=? WHERE cars.id_ = ?
('', 1)


> But without explicitly setting every field to its default value, the session 
> thinks nothing has changed and the UPDATE leaves most of the fields untouched.
> 
> Anyway, it appears I need a new approach to empty/blank a record. Options I 
> can think of are:

Here's the problem.  The term "a blank record" is meaningless.   You have to 
spell that out explicitly, on every class that has a concept of "blank".   
Class A might consider fields x, y, z but not q, p, r to be part of "blank", 
class B has some totally different idea.  Whether or not database fields have a 
"default" configured at the database level or table metadata level is also an 
artificial constraint...sure flip through table.c and look at default 
/server_default if you want that, but I've never written an app that had rules 
even that simplistic.

Trying to make other tools guess this for you seems to be taking up days of 
your time - whereas a simple def set_myself_blank(self) method OTOH would take 
30 seconds.


-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to