unnecessary column updates when type=boolean and value=false

Issue #324 resolved
Former user created an issue

Tested with postgresql 8.1 and sqlalchemy 0.2.8.

upon session.flush(), updates to table include fields that were not actually changed - specifically, fields of type boolean and value=false. Notice below how only the middle row has column c1 updated.

booltest.sql:

CREATE TABLE booltest (
    id integer NOT NULL PRIMARY KEY,
    c1 boolean,
    c2 char,
    c3 integer
);

insert into booltest values( 0, true, 'a', 10);
insert into booltest values( 1, false, 'b', 20);
insert into booltest values( 2, null, 'c', 30);

booltest.py:

from sqlalchemy import *

metadata = BoundMetaData('postgres://postgres@localhost/booltest')
metadata.engine.echo = True

booltest_table = Table('booltest', metadata, autoload=True)

class Booltest(object):
    pass

mapper(Booltest, booltest_table)

s = create_session()
q = s.query(Booltest)

results = q.select()

for r in results:
    r.c3 = 10 * r.c3

s.flush()

tail of output:

[18:16:51,519](2006-10-04) [engine](engine): BEGIN
[18:16:51,521](2006-10-04) [engine](engine): UPDATE booltest SET c3=%(c3)s WHERE booltest.id = %(booltest_id)s
[18:16:51,521](2006-10-04) [engine](engine): {'c3': 100, 'booltest_id': 0}
[18:16:51,524](2006-10-04) [engine](engine): UPDATE booltest SET c1=%(c1)s, c3=%(c3)s WHERE booltest.id = %(booltest_id)s
[18:16:51,524](2006-10-04) [engine](engine): {'c3': 200, 'c1': False, 'booltest_id': 1}
[18:16:51,527](2006-10-04) [engine](engine): UPDATE booltest SET c3=%(c3)s WHERE booltest.id = %(booltest_id)s
[18:16:51,527](2006-10-04) [engine](engine): {'c3': 300, 'booltest_id': 2}
[18:16:51,529](2006-10-04) [engine](engine): COMMIT

Comments (1)

  1. Log in to comment