[SQL-CVS] r1560 - in SQLObject/trunk/sqlobject: . tests
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: <sub...@co...> - 2006-02-03 19:06:20
|
Author: phd Date: 2006-02-03 12:06:10 -0700 (Fri, 03 Feb 2006) New Revision: 1560 Modified: SQLObject/trunk/sqlobject/dbconnection.py SQLObject/trunk/sqlobject/tests/test_select.py Log: Applied the patch 1422132: do not allow selectBy(nonexistantcolumn=foo). Modified: SQLObject/trunk/sqlobject/dbconnection.py =================================================================== --- SQLObject/trunk/sqlobject/dbconnection.py 2006-02-02 22:43:28 UTC (rev 1559) +++ SQLObject/trunk/sqlobject/dbconnection.py 2006-02-03 19:06:10 UTC (rev 1560) @@ -16,6 +16,7 @@ import sqlbuilder from cache import CacheSet import col +popKey = col.popKey from joins import sorter from converters import sqlrepr import classregistry @@ -682,16 +683,20 @@ ops = {None: "IS"} data = {} if 'id' in kw: - data[soClass.sqlmeta.idName] = kw['id'] + data[soClass.sqlmeta.idName] = popKey(kw, 'id') for key, col in soClass.sqlmeta.columns.items(): if key in kw: - data[col.dbName] = kw[key] + data[col.dbName] = popKey(kw, key) elif col.foreignName in kw: - obj = kw[col.foreignName] + obj = popKey(kw, col.foreignName) if obj is None: data[col.dbName] = None else: data[col.dbName] = obj.id + if kw: + # pick the first key from kw to use to raise the error, + raise TypeError, "got an unexpected keyword argument(s): %r" % kw.keys() + if not data: return None return ' AND '.join( Modified: SQLObject/trunk/sqlobject/tests/test_select.py =================================================================== --- SQLObject/trunk/sqlobject/tests/test_select.py 2006-02-02 22:43:28 UTC (rev 1559) +++ SQLObject/trunk/sqlobject/tests/test_select.py 2006-02-03 19:06:10 UTC (rev 1560) @@ -91,6 +91,13 @@ b = IterTest(name='b') assert IterTest.selectBy().count() == 2 +def test_selectBy_kwargs(): + setupClass(IterTest) + try: + b = IterTest(nonexistant='b') + except TypeError: + return + assert False, "IterTest(nonexistant='b') should raise TypeError" class Counter2(SQLObject): |