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

Exception when import query using Generic Setup #3

Open
nngu6036 opened this issue Oct 28, 2019 · 6 comments
Open

Exception when import query using Generic Setup #3

nngu6036 opened this issue Oct 28, 2019 · 6 comments

Comments

@nngu6036
Copy link

nngu6036 commented Oct 28, 2019

Import the contents rules for resource folder using Generic Setup throws exception

Content rules

   <rule name="rule-4" title="Trigger update on child resource when resource folder state change"
    cascading="False"
    description="When a resource folder workflow state is updated, it trigger another rule to update field parent_review_state of child resources ."
    enabled="True"
    event="Products.CMFCore.interfaces.IActionSucceededEvent"
    stop-after="False">
<conditions>
   <condition type="plone.conditions.PortalType">
    <property name="check_types">
     <element>resourcefolder</element>
    </property>
   </condition>
  </conditions>
  <actions>
   <action type="collective.contentrules.parentchild.ChildAction">
    <property name="query">
        <element>{"i": "portal_type", "o": "plone.app.querystring.operation.selection.any", "v": ["audio_resource", "external_resource", "resource", "video_resource"]}</element>
    </property>
    <property name="action_source">rule-3</property>
   </action>
  </actions>
 </rule>

This content rules is obtained using plone export in ZMI

Log

Traceback (most recent call last):
  File "/Users/quang.nguyen/buildout-cache/eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 366, in run_layer
    setup_layer(options, layer, setup_layers)
  File "/Users/quang.nguyen/buildout-cache/eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 628, in setup_layer
    setup_layer(options, base, setup_layers)
  File "/Users/quang.nguyen/buildout-cache/eggs/zope.testing-3.9.7-py2.7.egg/zope/testing/testrunner/runner.py", line 633, in setup_layer
    layer.setUp()
  File "/Users/quang.nguyen/buildout-cache/eggs/plone.app.testing-5.0.6-py2.7.egg/plone/app/testing/helpers.py", line 375, in setUp
    self.setUpPloneSite(portal)
  File "/Users/quang.nguyen/buildout_pretagovuk/src/plonetheme.mhcs/src/plonetheme/mhcs/testing.py", line 119, in setUpPloneSite
    theming.update()
  File "/Users/quang.nguyen/buildout-cache/eggs/plone.app.theming-1.3.6-py2.7.egg/plone/app/theming/browser/controlpanel.py", line 316, in update
    applyTheme(themeData)
  File "/Users/quang.nguyen/buildout-cache/eggs/plone.app.theming-1.3.6-py2.7.egg/plone/app/theming/utils.py", line 483, in applyTheme
    pluginSettings)
  File "/Users/quang.nguyen/buildout-cache/eggs/collective.themesitesetup-1.4.1-py2.7.egg/collective/themesitesetup/plugin.py", line 104, in onEnabled
    None, purge_old=False, archive=tarball)
  File "/Users/quang.nguyen/buildout-cache/eggs/Products.GenericSetup-1.8.8-py2.7.egg/Products/GenericSetup/tool.py", line 388, in runAllImportStepsFromProfile
    dependency_strategy=dependency_strategy)
  File "/Users/quang.nguyen/buildout-cache/eggs/Products.GenericSetup-1.8.8-py2.7.egg/Products/GenericSetup/tool.py", line 1433, in _runImportStepsFromContext
    message = self._doRunImportStep(step, context)
  File "/Users/quang.nguyen/buildout-cache/eggs/Products.GenericSetup-1.8.8-py2.7.egg/Products/GenericSetup/tool.py", line 1245, in _doRunImportStep
    return handler(context)
   - __traceback_info__: contentrules
  File "/Users/quang.nguyen/buildout_pretagovuk/src/plone.app.contentrules/plone/app/contentrules/exportimport/rules.py", line 405, in importRules
    importer.body = body
  File "/Users/quang.nguyen/buildout-cache/eggs/Products.GenericSetup-1.8.8-py2.7.egg/Products/GenericSetup/utils.py", line 512, in _importBody
    self._importNode(dom.documentElement)
  File "/Users/quang.nguyen/buildout_pretagovuk/src/plone.app.contentrules/plone/app/contentrules/exportimport/rules.py", line 189, in _importNode
    self._initRules(node)
  File "/Users/quang.nguyen/buildout_pretagovuk/src/plone.app.contentrules/plone/app/contentrules/exportimport/rules.py", line 286, in _initRules
    handler.import_element(action_node)
  File "/Users/quang.nguyen/buildout_pretagovuk/src/plone.app.contentrules/plone/app/contentrules/exportimport/rules.py", line 58, in import_element
    self.import_node(self.descriptor.schema, child)
  File "/Users/quang.nguyen/buildout_pretagovuk/src/plone.app.contentrules/plone/app/contentrules/exportimport/rules.py", line 104, in import_node
    field.validate(value)
  File "/Users/quang.nguyen/buildout-cache/eggs/zope.schema-4.4.2-py2.7.egg/zope/schema/_bootstrapfields.py", line 183, in validate
    self._validate(value)
  File "/Users/quang.nguyen/buildout-cache/eggs/zope.schema-4.4.2-py2.7.egg/zope/schema/_field.py", line 529, in _validate
    raise WrongContainedType(errors, self.__name__)
WrongContainedType: ([WrongType(u'\n        {"i": "portal_type", "o": "plone.app.querystring.operation.selection.any", "v": ["audio_resource", "external_resource", "resource", "video_resource"]}\n     ', <type 'dict'>, '')], 'query'
@djay
Copy link
Member

djay commented Oct 29, 2019

@nngu6036 presumably this is a bug with the PR #2 not the master plugin. But you don't say how you got that XML? It;s telling you it wants a dict and you are giving it a string so....

@djay
Copy link
Member

djay commented Oct 29, 2019

ah you say its from export. So maybe the query can be stored in a string?

@nngu6036
Copy link
Author

@djay , this XML from ZMI export not working with Generic Setup

<property name="query">
        <element>{"i": "portal_type", "o": "plone.app.querystring.operation.selection.any", "v": ["audio_resource", "external_resource", "resource", "video_resource"]}</element>
    </property>

If I change it to

<property name="query">
        [{"i": "portal_type", "o": "plone.app.querystring.operation.selection.any", "v": ["audio_resource", "external_resource", "resource", "video_resource"]}]
    </property>

The Generic Setup would not throws Exception, but then the rules query is not set

@djay
Copy link
Member

djay commented Nov 12, 2019

Was this patch installed at the time? if so the ZMI would be exporting different XML. plone/plone.app.contentrules#51.

@nngu6036
Copy link
Author

nngu6036 commented Nov 12, 2019

The exported XML after installing new pstach

 <action type="collective.contentrules.parentchild.ChildAction">
    <property name="query">
     <element>
      <element key="i">portal_type</element>
      <element key="o">plone.app.querystring.operation.selection.any</element>
      <element key="v">[u'audio_resource', u'external_resource', u'resource', u'video_resource']</element>
     </element>
    </property>
    <property name="action_source">rule-5</property>
   </action>

Use this XML to import, no exception thrown but the query is not correct

Screen Shot 2019-11-12 at 15 23 59

Export the rule gain

<action type="collective.contentrules.parentchild.ChildAction">
    <property name="query">
     <element>
      <element key="i">portal_type</element>
      <element key="o">plone.app.querystring.operation.selection.any</element>
      <element key="v">[u'audio_resource', u'external_resource', u'resource', u'video_resource']</element>
     </element>
    </property>
    <property name="action_source">rule-5</property>
   </action>

@djay
Copy link
Member

djay commented Nov 12, 2019

@instification in our usecase we can either

  1. just drop using a portal_type in teh query as we don't really need it
  2. stop using a query in this action and use another form of ancestor/decentent query configuration
  3. use the setproperty action directly and make it use more events different combinations of parents and children.
  4. Try to fix querywidget or supermodel to importexport correctly
  5. just don't worry about GS and install it manually.

If I got rid of query widget then I might use something like this

  • Level: what level of parent to include 0=this item, 1=parent, 2=grandparent, -1=root.
  • Depth: how many levels down to include. 0=just 1 item, 1=direct children, -1 all decedents.

I will also switch this to a condition and make it that when you choose the rule to act on the selected items, if you choose the current rule, then it will check both conditions and actions so you can use the content rule conditions to further filter the result set (even though this is more inefficient)

My suggest above means it will work for decedents and ancestors (more so than the current query widget) but won't work for the following cases

  • select all ancestors (without their children)
  • selecting a different part of the tree
  • selecting all siblings without the parent
  • other queries possible via the query widget like - find all items with certain keyword or type.

My preference is probably to stick to the querywidget as its the most flexible solution. It's path queries could be made more powerful in the future and the GS for it should be fixed in Plone (plone/plone.supermodel#31)

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

No branches or pull requests

2 participants