Content rule on portal root, no inheritance

Plone 5.0.5. I'm trying to add a rule where if a certain content type is created on the site root, it is moved to FolderA. This works except when I try to copy an object inside FolderA to a different path in FolderA. This results in a strange error - I can add more detail if you really want, but it seems to result in two calls to _setObj: my_object_id and my_object_id.1 and then tries to _getObj the first one which fails. Pasting is fine if I remove the rule.

Anyway, I don't actually want the rule to fire if inside FolderA. I only want it to work on the portal root. I thought perhaps I could add a TALES conditional here that does the equivalent of "context is portal" but documentation here is limited and I don't know what variables I have access to.

With Zope/Plone, you usually do not work with the objects themselves but with so called "acquisition wrapper"s, i.e. composite objects which contain the object and how they have been accessed. It is not safe to compare two acquisition wrappers with is: even if they wrap the same object and if the object was accessed in the same way, this is can return false (the is will only return true, if the two acquisition wrappers are in fact the same). You could try == (instead of is), it compares the wrapped objects.

To access the portal an object obj belongs to, you can use the view plone_portal_state. In a TALES path expression, this look like obj/@@plone_portal_state/portal, in a TALES Python expression obj.restrictedTraverse("@@plone_portal_state/portal").

So obj should be a bound variable here as opposed to context?

It seems that what I ultimately wanted was in fact possible anyway. You can't tell the rule itself to not be inherited, but when you assign the rule in some place there is an option "Disable apply to subfolders" which is what I wanted. Thanks

I do not know which variable names are bound in content rules. I used obj as a kind of placeholder for any object to show how to obtain the portal this object belongs to -- not that you should use obj as the variable name in your context. The likely name bound in content rules is context, maybe here, maybe object. Search for a content rule documentation or content rule examples to find out: they will tell you how the object can be accessed for which the content rule was fired.