Re: [SQLObject] Default Behaviour when notNull == False
SQLObject is a Python ORM.
Brought to you by:
ianbicking,
phd
From: Nick <ni...@dd...> - 2003-04-30 15:41:38
|
sorry, I send the wrong diff from an earlier try... this is the correct one. I'll also smack it in the message body so the list can see it. Nick Index: SQLObject/Col.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/Col.py,v retrieving revision 1.17 diff -u -u -r1.17 Col.py --- SQLObject/Col.py 29 Apr 2003 09:37:06 -0000 1.17 +++ SQLObject/Col.py 30 Apr 2003 15:38:38 -0000 @@ -20,7 +20,7 @@ def __init__(self, name=None, dbName=None, default=NoDefault, foreignKey=None, alternateID=False, alternateMethodName=None, - constraints=None, notNull=False, + constraints=None, notNull=True, unique=NoDefault): # This isn't strictly true, since we *could* use backquotes # around column names, but why would anyone *want* to Index: SQLObject/SQLObject.py =================================================================== RCS file: /cvsroot/sqlobject/SQLObject/SQLObject/SQLObject.py,v retrieving revision 1.30 diff -u -u -r1.30 SQLObject.py --- SQLObject/SQLObject.py 29 Apr 2003 09:47:48 -0000 1.30 +++ SQLObject/SQLObject.py 30 Apr 2003 15:38:39 -0000 @@ -674,7 +674,7 @@ # Then we check if the column wasn't passed in, and # if not we try to get the default. - if not kw.has_key(column.name): + if not kw.has_key(column.name) and column.notNull: default = column.default # If we don't get it, it's an error: ------- end of patch ------- On Wed, 2003-04-30 at 08:55, Brad Bollenbach wrote: > I have a class: > > class MerchantAccount(SQLObject): > _columns = [ > StringCol('merchantID', length = 15, alternateID = True, notNull = True), > StringCol('companyName', length = 50, notNull = True), > StringCol('address1', length = 255, notNull = False), > StringCol('address2', length = 255, notNull = False), > IntCol('telephone', notNull = False), > IntCol('fax', notNull = False), > StringCol('url', length = 100, notNull = False), > StringCol('lang', length = 6, notNull = False) > ] > MultipleJoin('MerchantProxyAccount') > > and then in a nearby piece of code, an insert: > > from merchant import MerchantAccount, MerchantProxyAccount, PurchaseTransaction > > ma = MerchantAccount.new(merchantID = "foo", companyName = "bar") > > When run, this raises an error: > > bradb@mothra:~/1ave/merchant/scripts$ python insert_test_data.py > Traceback (most recent call last): > File "insert_test_data.py", line 5, in ? > ma = MerchantAccount.new(merchantID = "desjardins", companyName = "Premiere Avenue") > File "/usr/lib/python2.2/site-packages/SQLObject/SQLObject.py", line 682, in new > raise TypeError, "%s did not get expected keyword argument %s" % (cls.__name__, repr(column.name)) > TypeError: MerchantAccount did not get expected keyword argument 'address1' > > Can we change the behaviour of this to "feel" more like an SQL insert, > so that if a column's allowed to be null, I don't have to specify it > in the new()? |