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

fix: Fix error when Plone site is not yet set as in first index_html call #21

Merged
merged 3 commits into from
Nov 29, 2024

Conversation

bsuttor
Copy link
Member

@bsuttor bsuttor commented Nov 27, 2024

In first index_html call on Zope, for example on http://localhost:8080/index_html, REQUEST for Plone Site is not yet set.
If you go directly on Plone, for example on http://localhost:8080/Plone/index_html, request is set to Plone Site (by acquisition) and you have not this error.

    ...
    z3c.jbot-2.0-py3.10.egg/z3c/jbot/utility.py", line 27, in getRequest
    return site.REQUEST
AttributeError: REQUEST

This fix is only usefull for first call on http://localhost:8080/index_html

@@ -24,7 +25,7 @@ def getRequest():
try:
return site.request
except AttributeError:
return site.REQUEST
return getattr(site, "REQUEST", Zope2.app().REQUEST)
Copy link
Member

Choose a reason for hiding this comment

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

This code always calls Zope2.app().REQUEST but it only seems to be needed in rare cases. I'd suggest to refactor this line, so Zope2.app().REQUEST is only computed when actually needed.

@d-maurer
Copy link

d-maurer commented Nov 28, 2024 via email

@bsuttor
Copy link
Member Author

bsuttor commented Nov 28, 2024

So Im' going to test "return None" instead of "return getattr(site, "REQUEST", Zope2.app().REQUEST)" on my use case. And if I haven't any errors I will change my PR

@d-maurer
Copy link

d-maurer commented Nov 28, 2024 via email

@bsuttor
Copy link
Member Author

bsuttor commented Nov 28, 2024

What about return getattr(site, "REQUEST", None)?

Indeed, lot better

@coveralls
Copy link

coveralls commented Nov 28, 2024

Pull Request Test Coverage Report for Build 12069008348

Details

  • 1 of 1 (100.0%) changed or added relevant line in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.2%) to 82.456%

Totals Coverage Status
Change from base Build 10028163829: -0.2%
Covered Lines: 350
Relevant Lines: 409

💛 - Coveralls

@icemac icemac requested a review from d-maurer November 29, 2024 06:49
@icemac icemac merged commit a0469d4 into master Nov 29, 2024
10 checks passed
@icemac icemac deleted the fix_plone_site_not_yet_set branch November 29, 2024 07:40
@icemac
Copy link
Member

icemac commented Nov 29, 2024

Just released in https://pypi.org/project/z3c.jbot/2.1/.

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

Successfully merging this pull request may close these issues.

4 participants