Re: [SQLObject] bug with sqlmeta.idName and non autoincrement primary keys?
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Vladimir B. <vla...@gm...> - 2005-11-09 16:54:14
|
Hi, if I look at the code where the exception is raised (col.py, def from_python(self, *value*, state)) I see the following check: if not isinstance(*value*, (int, long, sqlbuilder.SQLExpression)): raise validators.Invalid("expected an int in the IntCol '%s', got %s instead" % \ (self.name, type(value)), value, state) The problem here is that 'value' is '6', which is a string. Where does the string come from? It comes from mysqlconnection.py: def columnsFromSchema(self, tableName, soClass): colData =3D self.queryAll("SHOW COLUMNS FROM %s" % tableName)... MySql returns: (('person_id', 'int(11)', '', 'PRI', '6', ''), ('name', 'varchar(50)', '', '', '', '')) ---> '6' is the default value for column person_id The other question is, why is the default value for person_id passed as the value to from_python. That comes from the _create method in SQLObject: ... if not kw.has_key(column.name) and not kw.has_key(column.foreignName): default =3D column.default ... One thing I don't understand, why would we set persionId to the default value when we have passed id=3D22 in the constructor. Best regards, Vladimir On 11/9/05, Ian Bicking <ia...@co...> wrote: > Vladimir Blagojevic wrote: > > class Person(SQLObject): > > class sqlmeta: > > idName =3D 'person_id' > > table =3D 'person' > > fromDatabase =3D True > > > > class PersonTestCase(unittest.TestCase): > > > > def setUp(self): > > for person in Person.select(): > > person.destroySelf() > > > > def test_insert1(self): > > Person(id=3D1, name=3D'Paul') > > > > def test_insert2(self): > > Person(personID=3D1, name=3D'Paul') > > It looks like a combination of fromDatabase and idName is causing the > problem. There shouldn't be any personID column, that column should be > known as "id" on the Python side. So test_insert1 should work, > test_insert2 should give an error about an unexpected keyword argument. > > I'm guessing this is a bug in the MySQL fromDatabase code (or maybe all > fromDatabase code), because it should recognize which column is the id > based on idName. > > > -- > Ian Bicking / ia...@co... / http://blog.ianbicking.org > |