[SQL-CVS] r2019 - in SQLObject/trunk/sqlobject: . tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2006-10-12 14:52:43
|
Author: phd Date: 2006-10-12 08:52:38 -0600 (Thu, 12 Oct 2006) New Revision: 2019 Modified: SQLObject/trunk/sqlobject/main.py SQLObject/trunk/sqlobject/tests/test_auto.py Log: Fixed the bug 1463974: Column name collides with internal method. SQLObject now disallows columns with names that collide with existing methods, such as "_init", "expire", "set" and so on. Modified: SQLObject/trunk/sqlobject/main.py =================================================================== --- SQLObject/trunk/sqlobject/main.py 2006-10-12 13:55:46 UTC (rev 2018) +++ SQLObject/trunk/sqlobject/main.py 2006-10-12 14:52:38 UTC (rev 2019) @@ -318,8 +318,11 @@ "The class %s.%s already has a column %r (%r), you cannot " "add the column %r" % (soClass.__module__, soClass.__name__, name, - sqlmeta.columnDefinitions[name], - columnDef)) + sqlmeta.columnDefinitions[name], columnDef)) + assert name not in dir(soClass), ( + "The class %s.%s already has a variable or method %r, you cannot " + "add the column %r" + % (soClass.__module__, soClass.__name__, name, name)) sqlmeta.columnDefinitions[name] = columnDef sqlmeta.columns[name] = column # A stable-ordered version of the list... Modified: SQLObject/trunk/sqlobject/tests/test_auto.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_auto.py 2006-10-12 13:55:46 UTC (rev 2018) +++ SQLObject/trunk/sqlobject/tests/test_auto.py 2006-10-12 14:52:38 UTC (rev 2019) @@ -1,6 +1,8 @@ from sqlobject import * from sqlobject.tests.dbtest import * from sqlobject import classregistry +from py.test import raises + try: from datetime import datetime now = datetime.now @@ -62,6 +64,17 @@ Phone.sqlmeta.delColumn(col, changeSchema=True) Person.sqlmeta.delJoin(join) + def _test_collidingName(self): + class CollidingName(SQLObject): + expire = StringCol() + + def test_collidingName(self): + raises(AssertionError, Person.sqlmeta.addColumn, StringCol(name="name")) + raises(AssertionError, Person.sqlmeta.addColumn, StringCol(name="_init")) + raises(AssertionError, Person.sqlmeta.addColumn, StringCol(name="expire")) + raises(AssertionError, Person.sqlmeta.addColumn, StringCol(name="set")) + raises(AssertionError, self._test_collidingName) + ######################################## ## Auto class generation ######################################## |