Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TypeError: 'NoneType' object has no attribute '__getitem__' #105

Open
zopyx opened this issue Aug 25, 2016 · 3 comments
Open

TypeError: 'NoneType' object has no attribute '__getitem__' #105

zopyx opened this issue Aug 25, 2016 · 3 comments

Comments

@zopyx
Copy link
Member

zopyx commented Aug 25, 2016

Plone 5.0.5, plone.app.content 3.1.1

A DX content type with

class IPublication(model.Schema):

    connectors = RelationList(
        title=u"Connectors",
        default=[],
        value_type=RelationChoice(title=_(u"Connectors"),
                                  source=ObjPathSourceBinder()),
        required=True,
    )

leads to the following error as soon as you enter something into the auto-complete widget.


2016-08-25 13:55:47 ERROR Zope.SiteErrorLog 1472126147.580.27364738339 http://dev.zopyx.com:12020/Plonewqeqwe/foo/@@edit/++widget++form.widgets.connectors/@@getSource
Traceback (innermost last):
  Module ZPublisher.Publish, line 138, in publish
  Module ZPublisher.mapply, line 77, in mapply
  Module ZPublisher.Publish, line 48, in call_object
  Module plone.app.content.browser.vocabulary, line 217, in __call__
TypeError: 'NoneType' object has no attribute '__getitem__'
> self.parsed_query
> {'sort_on': u'sortable_title', 'sort_order': 'ascending', u'SearchableText': {'query': u'co*'}}
> len(results)
> 0
@gyst
Copy link
Member

gyst commented Oct 1, 2016

Confirmed on Plone 5.0.6 with plone.app.content 3.2.

The TypeError is raised when the following line tries to slice the path from val when val is None: https://github.com/plone/plone.app.content/blob/master/plone/app/content/browser/vocabulary.py#L220

I'm using a vanilla RelationChoice configured per the docs at
http://docs.plone.org/external/plone.app.dexterity/docs/advanced/references.html


@provider(IFormFieldProvider)
class ISectionReference(form.Schema):
    """A News Item reference to a news section, instead of containment.
    """

    section = RelationChoice(
        title=_(u"Section"),
        source=ObjPathSourceBinder(
            object_provides=INewsSection.__identifier__),
        required=False,
    )

The @getSource view on the widget works fine, even though this is where the log exception appears to come from; on direct call it returns:
{"total": 2, "results": [{"text": "Company News", "id": "/news/company-news"}, {"text": "Press Mentions", "id": "/news/press-mentions"}]}

@gyst
Copy link
Member

gyst commented Oct 1, 2016

Update: on inspection it turns out the TypeError is thrown when the widget queries for the path attribute:

@@getSource?query={"criteria":[{"i":"SearchableText","o":"plone.app.querystring.operation.string.contains","v":"com*"},{"i":"path","o":"plone.app.querystring.operation.string.path","v":"/news/company-news::1"}],"sort_on":"sortable_title","sort_order":"ascending"}&attributes=["UID","Title","portal_type","path","getURL","getIcon","is_folderish","review_state"]&batch={"page":1,"size":10}&_=1475311112907

@gyst
Copy link
Member

gyst commented Oct 1, 2016

Fix: replace ObjPathSourceBinder with CatalogSource.

from plone.app.vocabularies.catalog import CatalogSource

@provider(IFormFieldProvider)
class ISectionReference(form.Schema):
    """A News Item reference to a news section, instead of containment.
    """

    section = RelationChoice(
        title=_(u"Section"),
        source=CatalogSource(
            object_provides=INewsSection.__identifier__),
        required=False,
    )

This is a known documentation bug: plone/plone.app.dexterity#200

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants