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

Do not fail when request has no ensure_publishable method. #1206

Closed
wants to merge 1 commit into from

Conversation

mauritsvanrees
Copy link
Member

This may happen in tests.
In a Plone core development buildout with Zope master there are failures in plone.dexterity:

$ bin/test -s plone.dexterity -u
...
Error in test test_acquire_without_dav (plone.dexterity.tests.test_webdav.TestDAVTraversal.test_acquire_without_dav)
Traceback (most recent call last):
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/tests/test_webdav.py", line 1174, in test_acquire_without_dav
    r = traversal.publishTraverse(request, "item")
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/browser/traversal.py", line 40, in publishTraverse
    defaultTraversal = super().publishTraverse(request, name)
  File "/Users/maurits/community/plone-coredev/6.0/src/Zope/src/ZPublisher/BaseRequest.py", line 142, in publishTraverse
    self.request.ensure_publishable(subobject)
AttributeError: 'DAVTestRequest' object has no attribute 'ensure_publishable'

...

Error in test test_get_acquired (plone.dexterity.tests.test_webdav.TestDexterityPublishTraverse.test_get_acquired)
Traceback (most recent call last):
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/tests/test_webdav.py", line 1309, in test_get_acquired
    traversed = traversal.publishTraverse(self.get_request, "folder")
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/browser/traversal.py", line 40, in publishTraverse
    defaultTraversal = super().publishTraverse(request, name)
  File "/Users/maurits/community/plone-coredev/6.0/src/Zope/src/ZPublisher/BaseRequest.py", line 142, in publishTraverse
    self.request.ensure_publishable(subobject)
AttributeError: 'NoneType' object has no attribute 'ensure_publishable'

This could be fixed in the plone.dexterity tests. But I expect that there will be quite a few add-ons that have their own mock request class that has no ensure_publishable method.

This may happen in tests.
In a Plone core development buildout with Zope master there are failures in `plone.dexterity`:

```
$ bin/test -s plone.dexterity -u
...
Error in test test_acquire_without_dav (plone.dexterity.tests.test_webdav.TestDAVTraversal.test_acquire_without_dav)
Traceback (most recent call last):
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/tests/test_webdav.py", line 1174, in test_acquire_without_dav
    r = traversal.publishTraverse(request, "item")
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/browser/traversal.py", line 40, in publishTraverse
    defaultTraversal = super().publishTraverse(request, name)
  File "/Users/maurits/community/plone-coredev/6.0/src/Zope/src/ZPublisher/BaseRequest.py", line 142, in publishTraverse
    self.request.ensure_publishable(subobject)
AttributeError: 'DAVTestRequest' object has no attribute 'ensure_publishable'

...

Error in test test_get_acquired (plone.dexterity.tests.test_webdav.TestDexterityPublishTraverse.test_get_acquired)
Traceback (most recent call last):
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/Users/maurits/.pyenv/versions/3.11.7/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/tests/test_webdav.py", line 1309, in test_get_acquired
    traversed = traversal.publishTraverse(self.get_request, "folder")
  File "/Users/maurits/shared-eggs/cp311/plone.dexterity-3.0.5-py3.11.egg/plone/dexterity/browser/traversal.py", line 40, in publishTraverse
    defaultTraversal = super().publishTraverse(request, name)
  File "/Users/maurits/community/plone-coredev/6.0/src/Zope/src/ZPublisher/BaseRequest.py", line 142, in publishTraverse
    self.request.ensure_publishable(subobject)
AttributeError: 'NoneType' object has no attribute 'ensure_publishable'
```
@dataflake
Copy link
Member

It feels wrong to work around unittest mockup deficiencies in the "production" code.

@mauritsvanrees
Copy link
Member Author

Alternative PR for dexterity:
plone/plone.dexterity#198

Copy link
Contributor

@d-maurer d-maurer left a comment

Choose a reason for hiding this comment

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

In #1202 (comment),
I proposed an alternative approach.
I favor it even though it introduces a (hopefully minor) backward incompatibility (applications can no longer influence publication control by registering their own ITraversePublisher adapter),

@mauritsvanrees
Copy link
Member Author

Let me close this one, there is no enthusiasm for this approach.

@mauritsvanrees mauritsvanrees deleted the maurits-ensure-publishable branch April 24, 2024 15:36
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.

3 participants