-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Fix folder_contents being broken with VHM and Multilingual #18
Conversation
When Multilingual is enabled and VHM is enabled too, serving any folderish's `folder_contents` under a language folder as a top level domain name is currently broken (if `en.site.com/archives` is VHMed to `PloneSite/en/archives` then `@@qsOptions` URL is `/archives/@@qsOptions` instead of being `/@@qsOptions` as it should be. The fundamental problem is that the function `get_top_site_from_url(...)` is failing to retrieve the actual top site because it can't find a site in the traversal structure, so it picks the last folderish as the site, which is obvs broken because `/@@qsOptions` only works on site roots, not on folderish content. This code makes it so that any site found in the structure is returned as the top site from the URL, but if no top site is found in that traversal, the actual site from `getSite()` is returned instead, which is the correct behavior based on how the function is named, and actually fixes the `/@@qsOptions` conundrum.
@Rudd-O thanks for creating this Pull Request and helping to improve Plone! TL;DR: Finish pushing changes, pass all other checks, then paste a comment:
To ensure that these changes do not break other parts of Plone, the Plone test suite matrix needs to pass, but it takes 30-60 min. Other CI checks are usually much faster and the Plone Jenkins resources are limited, so when done pushing changes and all other checks pass either start all Jenkins PR jobs yourself, or simply add the comment above in this PR to start all the jobs automatically. Happy hacking! |
@jenkins-plone-org please run jobs |
Hold the merge for this, even if the tests pass. I have discovered an issue with the fix that needs to be addressed. EDIT: false alarm. This is good. |
@jenkins-plone-org please run jobs |
1 similar comment
@jenkins-plone-org please run jobs |
I have excellent news! Another thing that was legendarily broken in Multilingual sites (exactly because of this This code fixes it! OMG I have been five years without being able to insert things on my site unless I use an admin domain without VHM... and now I can! Pure joy. |
@jenkins-plone-org please run jobs |
Questions: (already answered: am preserving the behavior of the code, just including the topmost accessible object (rather than the bottommost only) in the list of objects to be considered as "site roots" to return to the caller.) Docs say use ISiteRoot https://docs.plone.org/develop/plone/serving/traversing.html#traversing-back-to-the-site-root I don't use VHM and Multilingual, so I don't have direct experience, and I'm not sure if I can deploy this into my env and actually test it. Will come back and edit this with more. More: God, I hate this code. That Try/Except block is huge.... I want to re-write this.... calm down.... |
From @flipmcf :
I honestly do not know :-)
We have a This function does not traverse from leaf to root. It traverses from root to leaf, starting with the rootmost element visible through the Web (VHM) and falling back to the actual Plone site root discovered through This code fixes the traversal so that we traverse from root to leaf, collecting any legit
Was already there. I did not change that.
I am wary of changing this.
Doesn't affect
I appreciate them! |
There really were a bunch of things that were utterly broken by the behavior of |
@jenkins-plone-org please run jobs |
The CI is dead folks. I will merge upon approval. I have the fix live running on locally and it works correctly with production VHM enabled. |
Should do some manual regressions on affected code - especially pre-release. As you say, get_top_site_from_url is used all over the place to do UI magic. The problem is, who is depending on the bad behavior of https://github.com/search?q=org%3Aplone+get_top_site_from_url&type=code I'm feeling that the safest (but not best) change is to repair If there is really a bug in the utility, then all code that depends on this utility needs to be notified, tested, and updated. This is indeed the correct path if @Rudd-O analyis is correct. I'm not able to verify that this analysis is correct (not saying it's incorrect, but that I simply can't verify) If we change this utility, I'm confident we'll be back here with someone else saying "Hey, this behavior changed that I was relying on". Maybe that's where we want to be, distributing the 'correct' work across the dependent code through finding and fixing failures, but in that case, we must be CERTAIN that get_top_site_from_url() is broken. I want another opinion on the hypotheses that |
CallsitesMy omelette is big. There are not that many uses, and all its uses currently broken are fixed by this patch. I count two uses:
Why this must return a content object in some cases, rather than an actual site rootThese two cases all need a "root object" from the perspective of the browser to compute a root for their own purposes, because all their purposes are browser stuff (fill lists of objects, chiefly). This method I'm fixing determines the "root" used for that tree which is used in related items, image insertion, and folder contents browsing, and if that "root" is incorrect / does not correspond to what the browser sees as "root", nothing works. Unit and regression testingAll current unit tests pass now. I have added a test case to cover the "root URL object is not actually a site" case, which was never tested before. In addition to that, I have tested this with a local build (most up to date code) and here is what I can verify:
So pretty much everything that was broken before, is no longer broken thanks to this modest change. And that is the complete manual regression test of all users of this code. |
I've added a new test case covering this exact issue. All tests pass. |
Now that tests are passing and the functionality of the site is working perfectly, I give myself some time to give a better rationale for this change as comments, for future me and future Plonistas.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch! And AFAICT a perfect solution. Bonus points for the doc-string improvement ;-)
@plone/framework-team should have a look here too i guess. Specially that nothing for restapi/Volto breaks here. |
This is so satisfying when a low-level fix happens. Congrats! I'm still going to wait on the complaints from those who may have relied on the incorrect behavior, but the analysis seems spot-on. Who would rely on something being broken in VHM environments? (we will find out!) @Rudd-O analysis is a good defense to anyone who finds this change offensive to them personally. |
Skimming the code it looks sane. |
This causes test failures. See Jenkins For now, I will remove Can't blame anyone for not seeing the test failures earlier, since PRs on Jenkins are broken currently. :-/ At least the standard jobs still work, so we see this after merge. |
This should fix the build for now. See plone/plone.base#18 (comment)
I read the tests and they (edit) do seem to be related to my fix. How can I run only the offending tests locally? I am using buildout and I want to bisect this. |
Figured it out thanks to @thet ! Please stand by for fixes... This package really should have CI. |
@mauritsvanrees I have replicated the test environment locally with my code, but basing my tests on The problem began appearing with 1.0.0b3 and my code. Will continue the bisect here. EDIT: somehow when I use mainline my fix does cause issues. So weird. |
I will work on this throughout the weekend. Please don't revert this fix just yet. |
I think I have a fix. Stand by for patch. Validating with the other test failures now. |
Broken tests: https://jenkins.plone.org/job/plone-6.0-python-3.10/763/ Fix: #19 The tests that were broken were retested locally using my own |
@Rudd-O great job! that must have been some deep diving. your analysis about how |
Thank you but I still broke the tests, and that is because I could not run them locally (I am now setup to run them here, so it's fine). A fix is incoming in #20 . |
When Multilingual is enabled and VHM is enabled too, serving any folderish's
folder_contents
under a language folder as a top level domain name is currently broken (ifen.site.com/archives
is VHMed toPloneSite/en/archives
then@@qsOptions
URL is/archives/@@qsOptions
instead of being/@@qsOptions
as it should be.The fundamental problem is that the function
get_top_site_from_url(...)
is failing to retrieve the actual top site because it can't find a site in the traversal structure, so it picks the last folderish as the site, which is obvs broken because/@@qsOptions
only works on site roots, not on folderish content.This code makes it so that any site found in the structure is returned as the top site from the URL, but if no top site is found in that traversal, the actual site from
getSite()
is returned instead, which is the correct behavior based on how the function is named, and actually fixes the/@@qsOptions
conundrum.Reproducer
Odd intersection of circumstances to reproduce bug:
Plone
site.en-US
or some other language./Plone
redirects toPlone/en-US
or your language folder of choice./Plone/en-US
is accessible as/
(a standard, supported Multilingual rewrite configuration typically used by Ploners for language-code subdomain hosting).Plone/en-US/VirtualHostRoot
is the relevant VHM rewrite./
.xxx
on that location.xxx
on that location.xxx
loads, but the actual listing remains empty.@@qsOptions
in the network panel of your browser inspector.Rationale
This code makes the method sometimes return a content object in some cases, rather than an actual site root.
Why?
All callsites (see below) need a "root object" from the perspective of the browser to compute a root and generate various URLs for their own purposes, because all their purposes are XHR browser stuff (fill lists of objects and search results, chiefly). This method I'm fixing determines the "root" used for that tree which is used in related items, image insertion, and folder contents browsing, and if that "root" is incorrect / does not correspond to what the browser sees as "root", nothing works.
Needless to say, this method should never be used to traverse anything server-side.
Quality control
Callsites
My omelette is big. There are not that many uses, and all its uses currently broken are fixed by this patch. I count two uses:
plone.app.content.browser.contents
:ContentsBaseAction
/get_options
/ContextInfo.call
plone.app.widgets
:get_relateditems_options
Unit and regression testing
All current unit tests pass now. I have added a test case to cover the "root URL object is not actually a site" case, which was never tested before. In addition to that, I have tested this with a local build (most up to date code) and here is what I can verify:
So pretty much everything that was broken before, is no longer broken thanks to this modest change. And that is the complete manual regression test of all users of this code.