[Z3-sqlos] problem with notNull=True on an attribute/column

Christian Lück christian.lueck at ruhr-uni-bochum.de
Sun Jan 22 21:01:17 CET 2006


Hi Brian,

it's me again. This time the problem seems more related to SQLObject
than to sqlos. It's a problem with the 'notNull' declaration for
attributes of SQLOS/SQLObject objects.
The problem appears, when you set notNull=True on an attribute and try
to create an object with the normal add-view ( <browser:addView> ).

To reproduce the error please refer to the simple Person app again. I
yust made little changes to the column definitions in
sqlosperson.person.Person - see attachement. -- You have to drop and
re-create the table first...

Traceback (innermost last):
  Module zope.publisher.publish, line 138, in publish
    result = publication.callObject(request, object)
  Module zope.app.publication.zopepublication, line 161, in callObject
    return mapply(ob, request.getPositionalArguments(), request)
  Module zope.publisher.publish, line 113, in mapply
    return debug_call(object, args)
   - __traceback_info__: <security proxied
zope.app.pagetemplate.simpleviewclass.SimpleViewClass from add.pt
instance at 0xb52bf38c>
  Module zope.publisher.publish, line 119, in debug_call
    return object(*args)
  Module zope.app.pagetemplate.simpleviewclass, line 44, in __call__
    return self.index(*args, **kw)
  Module zope.app.pagetemplate.viewpagetemplatefile, line 83, in __call__
    return self.im_func(im_self, *args, **kw)
  Module zope.app.pagetemplate.viewpagetemplatefile, line 51, in __call__
    sourceAnnotations=getattr(debug_flags, 'sourceAnnotations', 0),
  Module zope.pagetemplate.pagetemplate, line 117, in pt_render
    strictinsert=0, sourceAnnotations=sourceAnnotations)()
  Module zope.tal.talinterpreter, line 277, in __call__
    self.interpret(self.program)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 908, in do_useMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 538, in do_optTag_tal
    self.do_optTag(stuff)
  Module zope.tal.talinterpreter, line 523, in do_optTag
    return self.no_tag(start, program)
  Module zope.tal.talinterpreter, line 518, in no_tag
    self.interpret(program)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 976, in do_defineSlot
    self.interpret(block)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 966, in do_defineSlot
    self.interpret(slot)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 878, in do_defineMacro
    self.interpret(macro)
  Module zope.tal.talinterpreter, line 352, in interpret
    handlers[opcode](self, args)
  Module zope.tal.talinterpreter, line 588, in do_setLocal_tal
    self.engine.setLocal(name, self.engine.evaluateValue(expr))
  Module zope.tales.tales, line 696, in evaluate
    return expression(self)
   - /usr/local/Zope-3.2.0b2/lib/python/zope/app/form/browser/add.pt
   - Line 19, Column 8
   - Expression: <PathExpr standard:u'view/update'>
   - Names:
      {'args': (),
       'context': <zope.app.publisher.browser.viewmeta.+ object at
0xb52b022c>,
       'default': <object object at 0xb7d5b538>,
       'loop': {},
       'nothing': None,
       'options': {},
       'repeat': {},
       'request': <zope.publisher.browser.BrowserRequest instance
URL=http://localhost:8080/persons/+/AddPerson.html%3D>,
       'template':
<zope.app.pagetemplate.viewpagetemplatefile.ViewPageTemplateFile object
at 0xb66657cc>,
       'usage': <zope.pagetemplate.pagetemplate.TemplateUsage object at
0xb524f42c>,
       'view': <zope.app.pagetemplate.simpleviewclass.SimpleViewClass
from add.pt object at 0xb52bf38c>,
       'views': <zope.app.pagetemplate.viewpagetemplatefile.ViewMapper
object at 0xb525ea6c>}
  Module zope.tales.expressions, line 205, in __call__
    return self._eval(econtext)
  Module zope.tales.expressions, line 199, in _eval
    return ob()
  Module zope.app.form.browser.add, line 62, in update
    self.createAndAdd(data)
  Module zope.app.form.browser.add, line 93, in createAndAdd
    content = self.create(*args, **kw)
  Module zope.app.form.browser.add, line 74, in create
    return self._factory(*args, **kw)
  Module sqlobject.main, line 1179, in __init__
    self._create(id, **kw)
  Module sqlobject.main, line 1198, in _create
    raise TypeError, "%s() did not get expected keyword argument %s" %
(self.__class__.__name__, column.name)
TypeError: Person() did not get expected keyword argument username


I think the exception is due to the way objects are created in z3. They
first get instantiated and then the attributes are set in a second step.
SQLObject doesn't like that. It's in the doc there.

I don't know if there's a solution for that problem.

The thing I did: use zope.formlib for addviews and call a factory, which
instantiates objects with initial values. -- That was even the reason
why I registered a <zope:factory>. That's the whole story... ;-)


Kind regards,
Christian





-------------- next part --------------
A non-text attachment was scrubbed...
Name: sqlosperson.tgz
Type: application/x-compressed-tar
Size: 2727 bytes
Desc: not available
Url : http://codespeak.net/pipermail/z3-sqlos/attachments/20060122/653423e7/attachment.bin 


More information about the z3-sqlos mailing list