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

Simplify traversal #105

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open

Simplify traversal #105

wants to merge 8 commits into from

Conversation

thet
Copy link
Member

@thet thet commented Jun 6, 2020

by @petri
Opening this PR to be able to discuss it right here.

EDIT (petri) For background, see discussion in https://community.plone.org/t/json-application-messaging-in-plone-core/12353/11

@mister-roboto
Copy link

@thet thanks for creating this Pull Request and help improve Plone!

To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass.

Whenever you feel that the pull request is ready to be tested, either start all jenkins jobs pull requests by yourself, or simply add a comment in this pull request stating:

@jenkins-plone-org please run jobs

With this simple comment all the jobs will be started automatically.

Happy hacking!

@thet
Copy link
Member Author

thet commented Jun 7, 2020

@jenkins-plone-org please run jobs


# Wrap object to ensure we handle further traversal
return RESTWrapper(obj, request)
if IContentish.providedBy(obj) and not (
Copy link
Member

@petri petri Jun 7, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we check for ITraversable rather than or in addition to IContentish? Doing that seems to still solve plone/plone.restapi#680 and plone/plone.app.theming#165 (even when converted to IService!) whilst still passing at least plone.rest tests.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting. I'd guess that IContentish is always ITraversable. IContentish excludes the SiteRoot, not sure if that is traversable. Things are complex and different people worked on different parts that depend on plone.rest, so I'd like them to weight in as well. cc @buchi @jaroel @sneridagh

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actively remove IContentish from Plone Site in https://github.com/plone/Products.CMFPlone/pull/2612/files#diff-860754a57fed2533e4aae6aab34a27caR238-R242 . I did not check how that will affect plone.rest stuff, but so far it seemed to work.
My gut reaction is that ITraversable is correct here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're adding IContentish back to PloneSite.
I don't think this changes my position on ITraversable, but it probably will affect other stuff.

Is this whole branch/approach still relevant actually?

@tisto tisto requested a review from buchi June 8, 2020 07:21
petri added a commit that referenced this pull request Nov 2, 2020
@petri
Copy link
Member

petri commented Jan 28, 2021

@jenkins-plone-org please run jobs

jensens pushed a commit that referenced this pull request May 25, 2021
@jensens jensens force-pushed the simplify-traversal branch from 6e03466 to 66fcf2f Compare May 25, 2021 15:20
@jensens
Copy link
Member

jensens commented May 26, 2021

@jenkins-plone-org please run jobs

1 similar comment
@petschki
Copy link
Member

petschki commented Sep 6, 2021

@jenkins-plone-org please run jobs

@petschki
Copy link
Member

petschki commented Sep 6, 2021

@jenkins-plone-org please run jobs

@petschki
Copy link
Member

petschki commented Sep 6, 2021

@jenkins-plone-org please run jobs

1 similar comment
@petschki
Copy link
Member

petschki commented Sep 7, 2021

@jenkins-plone-org please run jobs

@petschki petschki self-assigned this Sep 7, 2021
@tisto
Copy link
Member

tisto commented Sep 7, 2021

@thet @petri @petschki could you elaborate on the background of this simplification? What's the actual use case here and the reasoning behind this PR?

The traversal mechanism has been subject to multiple refactorings in the past and it needs to cover multiple edge cases that we can not always put into proper unit tests. Changing this requires careful consideration and extensive testing and review. I'd like to understand the reasoning behind this for a proper tradeoff of the risks and chances here.

@petschki
Copy link
Member

petschki commented Sep 7, 2021

I'll try my best...

OLD strategy:

Try Zope's DefaultPublishTraverse first an catch it's KeyError as trigger to check for REST service or BrowserView and if nothing found re-raise KeyError to go back to the DefaulPublishTraverse again. The downside of this is, that the special isinstance check for VirtualHostMonster (and possibly other checks) have to be included in plone.rest traversal.

NEW strategy:

  1. Check for IService -> we can return this early
  2. Go with the DefaultPublishTraverse -> this raises KeyError (eg. if traversed name not found) and follows the default zope NotFound traversal mechanism
  3. Check for contentish objects -> wrap them with the RESTWrapper
  4. Last return object if it's something we do not cover (eg. VirtualHostMonster)

So this does exactly the same as before with the benefit of getting rid of the VirtualHostMonster (and possibly other objects) check. If there are missing special traversal objects/paths, they were missing before too. But they can be easily extended after step 3. and before step 4.

hope this helps.

@petschki
Copy link
Member

petschki commented Sep 7, 2021

NOTE: this branch is now on a Plone4.3/collective.exportimport migration project of us and works like a charm. The linage subsites delivered with VirtualHostMonster returns now plone.restapi JSON responses. Before there was this error:

"Resource not found: https://www.klaus.at/Plone/klaus/virtual_hosting"

/cc @thet I think you also had this one?

@petschki
Copy link
Member

petschki commented Sep 7, 2021

btw. the Jenkins jobs are flapping randomly ... yesterday it was https://jenkins.plone.org/job/pull-request-5.2-3.8/ today it's https://jenkins.plone.org/job/pull-request-5.2-2.7/ but I didn't change anything ... has anybody a clue on this?

/cc @jensens @rodfersou

@tisto
Copy link
Member

tisto commented Sep 7, 2021

Thanks for the clarification @petschki.

@buchi @sneridagh could you have a look at this PR?

@tisto tisto requested a review from sneridagh September 7, 2021 06:47
@petschki
Copy link
Member

petschki commented Sep 7, 2021

@jenkins-plone-org please run jobs

@petri
Copy link
Member

petri commented Sep 8, 2021

If someone wants to get some more background on this PR, I added a link to the discussion (see thet's original post at the beginning of this PR). It in turn has pointers to some earlier discussions. One thing worth mentioning is that the PR should also let plone.app.theming UI work properly again... afaik it has been partially non-functional ever since plone.rest was included with plone core.

@petri
Copy link
Member

petri commented Oct 6, 2021

@jenkins-plone-org please run jobs

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

Successfully merging this pull request may close these issues.

Traversing RESTWrapper with VirtualHostMonster raises KeyError
7 participants