I have an SQLObject model class like this:
class ResourceAccessRule(SQLObject):
    ...
    action = ForeignKey('ResourceAction', notNone=True, title="Action")
    resource = ForeignKey('Resource', notNone=True, title="Resource")

I used notNone=True to hint SQLObject that this field is required but in vain:

>>> ResourceAccessRule(action=None, resource=None)
  File 
"c:\python24\lib\site-packages\sqlobject-0.7.1dev_r1547-py2.4.egg\sqlobject\mysql\mysqlconnection.py",
    return cursor.execute(query)
  File "C:\Python24\lib\site-packages\MySQLdb\cursors.py", line 137, in execute
    self.errorhandler(self, exc, value)
  File "C:\Python24\lib\site-packages\MySQLdb\connections.py", line 33, in 
defaulterrorhandler
    raise errorclass, errorvalue
OperationalError: (1048, "Column 'action_id' cannot be null")

Is there a way to enforce non-None values in ctor?

So far I resorted to:

    def _create(self, id, **kw):
        if not kw.get('action'):
            raise ValueError('No action given')
        if not kw.get('resource'):
            raise ValueError('No resource given')
        super(ResourceAccessRule, self)._create(id, **kw)

Is there a better way?

Thanks,
Max.



-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid0944&bid$1720&dat1642
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss

Reply via email to