[SQLObject] Strange column type conversion
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Hong Y. <hon...@ho...> - 2005-01-02 17:23:40
|
I find that under some cercumstances a column declared as a certain type can return a different type as shown in the following sample code, tested with SQLObject 0.6.0 The test table, with PostgreSQL 7.4.6: CREATE TABLE test ( id int4 NOT NULL DEFAULT nextval('test_id_seq'::text), number int2 NOT NULL, CONSTRAINT pkey PRIMARY KEY (id) ) WITHOUT OIDS; ALTER TABLE test OWNER TO test; The test script: from sqlobject import * __connection__ = 'postgres://test:test@localhost/test?debug=0' class test(SQLObject): number = IntCol() for i in [3, 5, 8]: test(number = i) i = test.select(test.q.number == 8) i[0].number = '10' results = test.select() for r in results: print r.number, type(r.number) While I would expect the result to be all <type 'int'>, the actuall output is: 3 <type 'int'> 5 <type 'int'> 10 <type 'str'> It seems that sqlobject has remembered that the type of column 'number' was set to '10', a string type, though I thought IntCol should take care of converting the string to int before sending it to the SQL database. I think this kind of inconsistency of column return type will cause great confusion to the programms that use sqlobject and should be fixed. Best Regards Hong Yuan |