Choice()'s can take a string for their vocabulary, but lazr.restful can't handle this

Bug #412726 reported by Barry Warsaw
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
lazr.restful
Triaged
Low
Unassigned

Bug Description

I have the following field defined in my IMessageApproval interface:

    status = exported(Choice(
        title=_('Status'),
        description=_('The status of the held message.'),
        vocabulary='PostedMessageStatus',
        required=True))

Zope has no problem with this, but lazr.restful cannot find the
PostedMessageStatus enum:

    ...
      File "/home/barry/projects/launchpad/pristine/lib/zope/component/_api.py", line 207, in getUtility
    ComponentLookupError: (<InterfaceClass zope.schema.interfaces.IVocabularyFactory>, 'PostedMessageStatus')

However, if I change the field to use the actual enum, it works fine:

    status = exported(Choice(
        title=_('Status'),
        description=_('The status of the held message.'),
        vocabulary=PostedMessageStatus,
        required=True))

Output from my test...

      disposal_date: None
      disposed_by_link: None
      mailing_list_link: u'http://api.launchpad.dev/beta/~team-one/mailing_list'
      message_id: u'<aardvark>'
      posted_by_link: u'http://api.launchpad.dev/beta/~name16'
      posted_date: u'2000-08-01T01:08:59+00:00'
      resource_type_link: u'http://api.launchpad.dev/beta/#message_approval'
      self_link: u'http://api.launchpad.dev/beta/~team-one/mailing_list/<aardvark>'
      status: u'New status'

In this particular case, it's fine to change the vocabulary argument from the
string to the enum, but this won't always be the case due to circular
references.

Revision history for this message
Barry Warsaw (barry) wrote :
Download full text (3.8 KiB)

Full traceback

    pprint_collection(messages)
Exception raised:
    Traceback (most recent call last):
      File "/home/barry/projects/launchpad/pristine/lib/zope/testing/doctest.py", line 1360, in __run
        save_stdout = sys.stdout
      File "<doctest xx-message-holds.txt[17]>", line 1, in ?
      File "/home/barry/projects/launchpad/385180-mmapi/lib/lazr/restful/testing/webservice.py", line 132, in pprint_collection
        collection = collection.jsonBody()
      File "/home/barry/projects/launchpad/385180-mmapi/lib/lazr/restful/testing/webservice.py", line 435, in jsonBody
        raise ValueError(self.getOutput())
    ValueError: HTTP/1.1 500 Internal Server Error
    Content-Length: 2990
    Content-Type: text/plain
    X-Lazr-Oopsid: OOPS-1320T17

    (<InterfaceClass zope.schema.interfaces.IVocabularyFactory>, 'PostedMessageStatus')

    Traceback (most recent call last):
      File "/home/barry/projects/launchpad/pristine/lib/zope/publisher/publish.py", line 133, in publish
      File "/home/barry/projects/launchpad/385180-mmapi/lib/lazr/restful/publisher.py", line 154, in callObject
        value = super(
      File "/home/barry/projects/launchpad/385180-mmapi/lib/canonical/launchpad/webapp/publication.py", line 373, in callObject
        return mapply(ob, request.getPositionalArguments(), request)
      File "/home/barry/projects/launchpad/pristine/lib/zope/publisher/publish.py", line 108, in mapply
      File "/home/barry/projects/launchpad/pristine/lib/zope/publisher/publish.py", line 114, in debug_call
      File "/home/barry/projects/launchpad/devel/lib/lazr/restful/_resource.py", line 820, in __call__
        result = self.do_GET()
      File "/home/barry/projects/launchpad/devel/lib/lazr/restful/_resource.py", line 1294, in do_GET
        result = self.handleCustomGET(operation_name)
      File "/home/barry/projects/launchpad/devel/lib/lazr/restful/_resource.py", line 628, in handleCustomGET
        return operation()
      File "/home/barry/projects/launchpad/pristine/lib/lazr/restful/_operation.py", line 59, in __call__
      File "/home/barry/projects/launchpad/pristine/lib/lazr/restful/declarations.py", line 833, in call
      File "/home/barry/projects/launchpad/pristine/lib/lazr/restful/_operation.py", line 94, in encodeResult
      File "/home/barry/projects/launchpad/eggs/simplejson-2.0.9-py2.4-linux-i686.egg/simplejson/__init__.py", line 236, in dumps
        separators=separators, encoding=encoding, default=default,
      File "/home/barry/projects/launchpad/eggs/simplejson-2.0.9-py2.4-linux-i686.egg/simplejson/encoder.py", line 200, in encode
        chunks = self.iterencode(o, _one_shot=True)
      File "/home/barry/projects/launchpad/eggs/simplejson-2.0.9-py2.4-linux-i686.egg/simplejson/encoder.py", line 260, in iterencode
        return _iterencode(o, 0)
      File "/home/barry/projects/launchpad/devel/lib/lazr/restful/_resource.py", line 131, in default
        return IJSONPublishable(obj).toDataForJSON()
      File "/home/barry/projects/launchpad/devel/lib/lazr/restful/_resource.py", line 1227, in toDataForJSON
        return self.toDataStructure(self.JSON_TYPE)
      File "/home/barry/projects/launchp...

Read more...

Changed in lazr.restful:
status: New → Triaged
importance: Undecided → Low
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.