Problem with a Collection object that was instantiated via the Plone API

I created a Collection object and posted it to the ZODB via the Plone API. The object instantiated, but when I tried to view it, I got the following message:

    Traceback (innermost last):
  Module ZPublisher.WSGIPublisher, line 162, in transaction_pubevents
  Module ZPublisher.WSGIPublisher, line 359, in publish_module
  Module ZPublisher.WSGIPublisher, line 254, in publish
  Module ZPublisher.mapply, line 85, in mapply
  Module ZPublisher.WSGIPublisher, line 63, in call_object
  Module zope.browserpage.simpleviewclass, line 41, in __call__
  Module Products.Five.browser.pagetemplatefile, line 126, in __call__
  Module Products.Five.browser.pagetemplatefile, line 58, in __call__
  Module zope.pagetemplate.pagetemplate, line 133, in pt_render
  Module Products.PageTemplates.engine, line 367, in __call__
  Module z3c.pt.pagetemplate, line 176, in render
  Module chameleon.zpt.template, line 307, in render
  Module chameleon.template, line 214, in render
  Module chameleon.utils, line 75, in raise_with_traceback
  Module chameleon.template, line 192, in render
  Module f73d060100d62f9f501ab5d4cdb241e6, line 1982, in render
  Module 855b424d543568ea95506c22e704ab24, line 860, in render_master
  Module 855b424d543568ea95506c22e704ab24, line 1489, in render_content
  Module f73d060100d62f9f501ab5d4cdb241e6, line 1967, in __fill_content_core
  Module f73d060100d62f9f501ab5d4cdb241e6, line 122, in render_content_core
  Module f73d060100d62f9f501ab5d4cdb241e6, line 390, in render_listing
  Module zope.tales.expressions, line 250, in __call__
  Module Products.PageTemplates.Expressions, line 196, in _eval
  Module Products.PageTemplates.Expressions, line 126, in render
  Module plone.app.contenttypes.browser.collection, line 47, in batch
  Module plone.app.contenttypes.browser.collection, line 42, in results
  Module plone.app.contenttypes.behaviors.collection, line 114, in results
  Module plone.app.querystring.querybuilder, line 89, in __call__
  Module plone.app.querystring.querybuilder, line 120, in _makequery
  Module plone.app.querystring.querymodifiers, line 16, in modify_query_to_enforce_navigation_root
  Module plone.app.querystring.querymodifiers, line 17, in <genexpr>
TypeError: string indices must be integers

 - Expression: "view/batch"
 - Filename:   ... .egg/plone/app/contenttypes/browser/templates/listing.pt
 - Location:   (line 22: col 31)
 - Source:     <tal:results define="batch view/batch;
                                          ^^^^^^^^^^
 - Expression: "provider:plone.abovecontentbody"
 - Filename:   ... egg/Products/CMFPlone/browser/templates/main_template.pt
 - Location:   (line 94: col 70)
 - Source:     ... 
                                     ^
 - Expression: "context/@@main_template/macros/master"
 - Filename:   ... .egg/plone/app/contenttypes/browser/templates/listing.pt
 - Location:   (line 6: col 21)
 - Source:     ... tal:use-macro="context/@@main_template/macros/master"
                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 - Arguments:  template: <Products.Five.browser.pagetemplatefile.ViewPageTemplateFile object at 0x7fadde5f19d0>
               options: {}
               args: ()
               nothing: None
               modules: <Products.PageTemplates.ZRPythonExpr._SecureModuleImporter object at 0x7fadf0bc92b0>
               request: <WSGIRequest, URL=http://ontology.texasbusinesslaw.org/statutes/united-states/federal/united-states-code-u-s-c/11-u-s-c/11-u-s-c-ss102/listing_view>
               view: <Products.Five.browser.metaconfigure.SimpleViewClass from /opt/plone/buildout-cache/eggs/plone.app.contenttypes-2.1.10-py3.8.egg/plone/app/contenttypes/browser/templates/listing.pt object at 0x7fadcdb6b580>
               context: <Collection at /data/statutes/united-states/federal/united-states-code-u-s-c/11-u-s-c/11-u-s-c-ss102>
               views: <Products.Five.browser.pagetemplatefile.ViewMapper object at 0x7fadcdb6bac0>
               here: <Collection at /data/statutes/united-states/federal/united-states-code-u-s-c/11-u-s-c/11-u-s-c-ss102>
               container: <Collection at /data/statutes/united-states/federal/united-states-code-u-s-c/11-u-s-c/11-u-s-c-ss102>
               root: <Application at >
               traverse_subpath: []
               user: <PloneUser 'ronc'>
               default: <DEFAULT>
               repeat: <Products.PageTemplates.engine.RepeatDictWrapper object at 0x7fadcd2bf8c0>
               loop: {}
               target_language: None
               translate: <function BaseTemplate.render.<locals>.translate at 0x7fadcfde0a60>
               macroname: 'master'
               attrs: {}

Note, the code to create the object was:

    obj = api.content.create(type='Collection', title=Title, description=Description, subjects=Subjects, query=Query, text=RichTextValue(Text, 'text/plain', 'text/html'), container=container)

Now I had crated several thousand Folder and Document objects with similar code (and all were viewable just fine), but the only difference with the Collections objects were the addition of the query and subjects. In this case, the subjects tuple was a single element, created by:

`Subjects = (Title,)`

... and the Query parameter was created by:

`Query = [Title]`

... which I would have thought would have been okay. Clearly, however, that was not the case. Any idea what the problem might be? My guess is that the query parameter is wrong.

To answer my own question (partially). There is a problem with both the query and the subjects. As a test, I removed the query parameter and that cleared up the viewing problem. Unfortunately, keeping the subjects parameter didn't fix the problem as none of the of the Tags shows up in the Classification tab.

With respect to query, I think there is some type of list syntax that I'm not finding in the documentation. An example would go a long way to illuminating what's necessary in that list. I'm assuming that it is "contents" or "tag" followed by some value. Is this supposed to be a list of dictionaries?

Worse, does the tag have to be available before you can correctly set the criteria for that collection object? That's the way it is currently, but only for the user interface (you have to have set the Tag first, before you can set a "Tag" criteria to the right tag.

This syntax is defined by plone.app.querystring. There is no documentation for that, but you can take a look at the tests to see how to create a query string: https://github.com/plone/plone.app.querystring/blob/master/plone/app/querystring/tests/testQueryBuilder.py#L75

What I sometimes do is: create the Collection in Plone with all query params I need and then inspect the object using pdb.

query is a sequence of mappings. Keys are 'i' (specifying the index), 'v' (specifying the value[s]) and 'o' (specifying the operation),

The available operations are described in the registry as the records for interface plone.app.querystring.interfaces.IQueryOperation. The default operations are registered by plone.app.querystring:profiles/default/registry.xml.

plone.restapi gives good hints here https://plonerestapi.readthedocs.io/en/latest/querystringsearch.html

And with it one can query a list of all configured options as well here:
https://plonerestapi.readthedocs.io/en/latest/querystring.html