← Back to team overview

lazr-users team mailing list archive

Re: Using lazr.restful with a zope3 app

 

The problem was really the __repr__ of z3c.form. I fixed it and things
worked fine. Will contact z3c.form owner for a permanent fix
Now zope.app.publication and z3c.form need fixes...

So, one step closer but still not there. At least now it seems i'm really on
lazr.restful space. I'm having problems with the following:

   lazr/restful/_resource.py(1887)toDataForJSON()
   1886         for link_name, publication in publications.items():
-> 1887             data_for_json[link_name] = absoluteURL(publication,
   1888                                                    self.request)

absoluteURL call fails with TypeError: There isn't enough context to get URL
information
Here is what the various objects look like:

ipdb> publications
Out[0]: {'systems_collection_link': <tp4.portal.restful.resources.SystemSet
object at 0xaf14d6c>}
ipdb> publication
Out[0]: <tp4.portal.restful.resources.SystemSet object at 0xaf14d6c>
ipdb> self.request
Out[0]: <lazr.restful.simple.Request instance URL=
http://localhost:8080/api/1.0>

My RootResource is:

class WebServiceRootResource(RootResource):
    """The root resource for a web service."""

    def _build_top_level_objects(self):
        systemset = SystemSet()
        systemset.systems = [
            System(systemset, "foo", "bar"),
            System(systemset, "1", "2")
            ]
        collections = dict(systems=(ISystem, systemset))
        return collections, {}

Configuration:

class WebServiceConfiguration(BaseWebServiceConfiguration):
    code_revision = '1'
    active_versions = ['1.0',]
    use_https = False
    last_version_with_mutator_named_operations = None
    view_permission = 'zope.Public'
    service_root_uri_prefix = "api/"
    hostname = "localhost"
    port = "8080"


Thoughts?

Thanks



2010/6/21 Gary Poster <gary.poster@xxxxxxxxxxxxx>

>
> On Jun 21, 2010, at 11:37 AM, Gustavo Rahal wrote:
>
> >
> > Thanks, it indeed worked out.
>
> Awesome.
>
> > I think there is even a bug on zope.app.publication. Asked zope-dev for
> comments
>
> I just looked at that.  It does sound suspicious, yes.  (I'd suggest you
> using .sort rather than sorted in this case, but that's trivial.)  I'm going
> to hope someone else follows up, so I don't get bogged down there, but if
> you decide you need to kick someone to get attention on it, I guess I'm
> willing to be kicked. :-)
>
> > So, now I have another problem that seems more obscure. I'm using
> lazr.restfulclient and did a call to /api/
> >
> > ---
> > Response body:
> > ---
> > maximum recursion depth exceeded
> >
> > Traceback (most recent call last):
> >   File
> "/home/grahal/.buildout/eggs/zope.publisher-3.4.6-py2.5.egg/zope/publisher/publish.py",
> line 133, in publish
> >     result = publication.callObject(request, obj)
> >   File
> "/home/grahal/devel/eclipse-workspace/virtualenv/lazr.restful/src/lazr/restful/publisher.py",
> line 171, in callObject
> >     WebServicePublicationMixin, self).callObject(request, object)
> >   File
> "/home/grahal/devel/eclipse-workspace/virtualenv/lazr.restful/src/lazr/restful/simple.py",
> line 113, in callObject
> >     return mapply(ob, request.getPositionalArguments(), request)
> >   File
> "/home/grahal/.buildout/eggs/zope.publisher-3.4.6-py2.5.egg/zope/publisher/publish.py",
> line 108, in mapply
> >     return debug_call(obj, args)
> >   File
> "/home/grahal/.buildout/eggs/zope.publisher-3.4.6-py2.5.egg/zope/publisher/publish.py",
> line 114, in debug_call
> >     return obj(*args)
> >   File
> "/home/grahal/devel/eclipse-workspace/virtualenv/lazr.restful/src/lazr/restful/_resource.py",
> line 1739, in __call__
> >     result = self.do_GET()
> >   File
> "/home/grahal/devel/eclipse-workspace/virtualenv/lazr.restful/src/lazr/restful/_resource.py",
> line 1780, in do_GET
> >     result = self.toWADL().encode("utf-8")
> >   File
> "/home/grahal/devel/eclipse-workspace/virtualenv/lazr.restful/src/lazr/restful/_resource.py",
> line 1801, in toWADL
> >     for registration in sorted(site_manager.registeredAdapters()):
> >   File
> "/home/grahal/.buildout/eggs/zope.component-3.4.0-py2.5.egg/zope/component/registry.py",
> line 435, in __cmp__
> >     return cmp(self.__repr__(), other.__repr__())
> >   File
> "/home/grahal/.buildout/eggs/zope.component-3.4.0-py2.5.egg/zope/component/registry.py",
> line 431, in __repr__
> >     getattr(self.factory, '__name__', `self.factory`), self.info,
> >   File
> "/home/grahal/.buildout/eggs/z3c.form-2.2.0-py2.5.egg/z3c/form/button.py",
> line 65, in __repr__
> >     self.__class__.__name__, self.__name__, self.title)
> >   File
> "/home/grahal/.buildout/eggs/z3c.form-2.2.0-py2.5.egg/z3c/form/button.py",
> line 65, in __repr__
> >     self.__class__.__name__, self.__name__, self.title)
> >   [...]
> > RuntimeError: maximum recursion depth exceeded
> >
> >
> > The call to site_manager.registeredAdapters() is what cause this problem.
> Any ideas?
>
> I think actually it's the call to sorted on the result of
> registeredAdapters().
>
> The core problem is that the z3c/form/button.py object, whatever it is, has
> a broken repr.  A broken repr is just unacceptable IMO.
>
> This code is trying to generate WADL.  It wants the WADL output to be
> stable, so it sorts.  It could probably sort something else further down the
> chain, but what it is doing now is entirely reasonable, so it's hard to
> argue for a change to accommodate a broken repr.  The z3c.form bits should
> be fixed, is my take.
>
> Gary

Follow ups

References