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

Use INameFromTitle interface from plone.base #379

Closed
wants to merge 4 commits into from

Conversation

gforcada
Copy link
Sponsor Contributor

This is part of plone/Products.CMFPlone#3858

It needs plone/plone.base#51 to be merged, and released.

It first needs #378 to be merged first.

See the tracking issue for the overview of the changes and why.

@mister-roboto
Copy link

@gforcada thanks for creating this Pull Request and helping to improve Plone!

TL;DR: Finish pushing changes, pass all other checks, then paste a comment:

@jenkins-plone-org please run jobs

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!

@mauritsvanrees mauritsvanrees marked this pull request as ready for review October 25, 2023 15:18
@mauritsvanrees
Copy link
Sponsor Member

I have released a new plone.base version and updated the constraints at https://dist.plone.org/release/6.0-dev/ so should be fine now.
I will test this together with plone/plone.app.content#271 on Jenkins.

@mauritsvanrees
Copy link
Sponsor Member

Actually, tox -e test fails, so that needs to be fixed first.

@mauritsvanrees
Copy link
Sponsor Member

Failure seems related:

Failure in test test_add_item_w_title_only (plone.app.dexterity.behaviors.tests.test_id.TestShortNameBehavior.test_add_item_w_title_only)
Traceback (most recent call last):
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 57, in testPartExecutor
    yield
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 623, in run
    self._callTestMethod(testMethod)
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 579, in _callTestMethod
    if method() is not None:
  File "/Users/maurits/community/plone-coredev/6.0/src/plone.app.dexterity/plone/app/dexterity/behaviors/tests/test_id.py", line 58, in test_add_item_w_title_only
    self.assertEqual(self.browser.url, "http://nohost/plone/id-from-title")
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 873, in assertEqual
    assertion_func(first, second, msg=msg)
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 1253, in assertMultiLineEqual
    self.fail(self._formatMessage(msg, standardMsg))
  File "/usr/local/Cellar/python@3.11/3.11.6/Frameworks/Python.framework/Versions/3.11/lib/python3.11/unittest/case.py", line 703, in fail
    raise self.failureException(msg)
AssertionError: 'http://nohost/plone/document' != 'http://nohost/plone/id-from-title'
- http://nohost/plone/document
?                       --  --
+ http://nohost/plone/id-from-title
?                     + +++  +++++

I did not dive in, and probably won't do that today. @gforcada ?

@davisagli
Copy link
Sponsor Member

@mauritsvanrees @gforcada I tried to take a look at this, but the tests pass for me in buildout.coredev, and when I try tox -e test I get a different, bizarre error:

Test-module import failures:

Module: .tox.test.lib.python3.9.site-packages.plone.app.dexterity.behaviors.tests.test_contrains

ModuleNotFoundError: No module named '.tox'

@mauritsvanrees
Copy link
Sponsor Member

@davisagli The tests pass for me in coredev 6.1, but not in 6.0.
I have not seen the ModuleNotFoundError: No module named '.tox' error.

Of course one thing that still needs to happen, is that this needs to be tested in combination with plone/plone.app.content#271. But even then, when I run the 6.0 tests with both branches checked out, it fails in the same way as here in gh-actions.

It seems to work fine in practice though: when I fire up an instance and create a new Image and a new Page, they both get a normalised id based on the file name or the page title.

So I wonder if something is wrong in test setup, that some zcml is not loading, but I don't see what it would be.

@mauritsvanrees
Copy link
Sponsor Member

Okay, I kind-of see what is going on, but not completely.

In plone/app/dexterity/tests/namefromtitle.txt we have created a portal_type and added some behaviors. At first this was plone.app.content.interfaces.INameFromTitle, which worked, but in this PR we of course change this to plone.base.interfaces.INameFromTitle.
This somehow does not work. But the previous setting no longer works either.

The way to fix this in the test, is to use the named behavior plone.namefromtitle. Tests then pass, case closed.

But the problem then remains: if there is a site that uses this behavior by interface, either the old or the new one, then it fails.

Maybe someone can come up with a combination that works, but I could not. I think we need to postpone this PR and plone/plone.app.content#271 until at least Plone 6.1, and maybe 7.0.

What might help, is one of the following, probably somewhere in plone.behavior or plone.dexterity:

  • If someone sets the behaviors property of an FTI, automatically convert interfaces to named behaviors if available, and save this to the database.
  • Do the same, but do this when reading the property. Could be expensive as this is used a lot when reading attributes from a content type. Possibly change it on-the-fly, but that would be a write-on-read.
  • Have an upgrade step that goes through all FTIs and fixes this. But this is one-time only and then an add-on could still use an interface name and then it fails again.

Wait, would former_dotted_names in the behavior registration help? No, it does not. I tried it like this:

  <!-- Title-to-id -->
  <plone:behavior
      name="plone.namefromtitle"
      title="Name from title"
      description="Automatically generate short URL name for content based on its initial title"
      provides="plone.base.interfaces.INameFromTitle"
      former_dotted_names="plone.app.content.interfaces.INameFromTitle plone.base.interfaces.INameFromTitle"
      />

Ah but this is used in lookup_behavior_registration which is only called when you go the the Types Control Panel and go to the Behaviors tab of a type. And there it does not help either: when I have the interface in the behaviors in the ZMI, the plone.nameformtitle behavior is not checked in the Plone UI.

@mauritsvanrees
Copy link
Sponsor Member

@gforcada @davisagli We may need to revert the plone.base change: the INameFromTitle there has no effect if people use it, unless we merge these two PRs, but as explained I am currently against that... What do you think?

I would be happy to be shown an error in my logic.

mauritsvanrees added a commit that referenced this pull request Oct 31, 2023
This is for `INameFromTitle`, which we want to move to `plone.base`.
See #379 (comment) for why this is not working yet, and we need this workaround.
mauritsvanrees added a commit that referenced this pull request Oct 31, 2023
This is for `INameFromTitle`, which we want to move to `plone.base`.
See #379 (comment) for why this is not working yet, and we need this workaround.
mauritsvanrees added a commit that referenced this pull request Oct 31, 2023
This is for `INameFromTitle`, which we want to move to `plone.base`.
See #379 (comment) for why this is not working yet, and we need this workaround.
@mauritsvanrees
Copy link
Sponsor Member

I have created a PR to make plone.app.content a conditional dependency of plone.app.dexterity, so at least the circular dependency is broken: #380

For the moment in Plone 6.0.8 we could revert plone.base to 1.1.4.

@davisagli
Copy link
Sponsor Member

@mauritsvanrees I think you are on the right track. Earlier I missed that the old interface location could be stored somewhere persistently.

There isn't much harm in leaving the INameFromTitle in plone.base, except for potential confusion. We could leave it there and update INameFromTitle in plone.app.content to extend it, so that we're at least moving in the intended direction.

@mauritsvanrees
Copy link
Sponsor Member

Closed in favour of PR #380.

mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Nov 2, 2023
Branch: refs/heads/master
Date: 2023-10-15T17:57:43+02:00
Author: Gil Forcada Codinachs (gforcada) <gil.gnome@gmail.com>
Commit: plone/plone.app.content@85a904c

feat: deprecate INameFromTitle in this distribution

It got moved to `plone.base`.

Adds a deprecation warning so the interface can be moved right away, but
does not break other code that still imports from here, and show a
deprecation warning about it.

Files changed:
M plone/app/content/interfaces.py
M plone/app/content/namechooser.py
M plone/app/content/namechooser.txt
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-10-15T17:59:36+02:00
Author: Gil Forcada Codinachs (gforcada) <gil.gnome@gmail.com>
Commit: plone/plone.app.content@de83c82

Add news entry

Files changed:
A news/3858.internal.2
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-10-25T17:18:41+02:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.content@9a9dbf3

Merge branch 'master' into use-interface-from-plone-base

Files changed:
A .editorconfig
A .flake8
A .github/workflows/meta.yml
A .meta.toml
A .pre-commit-config.yaml
A tox.ini
M .gitignore
M CHANGES.rst
M plone/app/content/browser/actions.py
M plone/app/content/browser/configure.zcml
M plone/app/content/browser/constraintypes.pt
M plone/app/content/browser/constraintypes.py
M plone/app/content/browser/content_status_history.py
M plone/app/content/browser/contents/__init__.py
M plone/app/content/browser/contents/configure.zcml
M plone/app/content/browser/contents/copy.py
M plone/app/content/browser/contents/cut.py
M plone/app/content/browser/contents/delete.py
M plone/app/content/browser/contents/paste.py
M plone/app/content/browser/contents/properties.py
M plone/app/content/browser/contents/rename.py
M plone/app/content/browser/contents/tags.py
M plone/app/content/browser/contents/workflow.py
M plone/app/content/browser/folderfactories.pt
M plone/app/content/browser/full_review_list.pt
M plone/app/content/browser/i18n.py
M plone/app/content/browser/interfaces.py
M plone/app/content/browser/selection.py
M plone/app/content/browser/table.pt
M plone/app/content/browser/table.txt
M plone/app/content/browser/templates/content_status_history.pt
M plone/app/content/browser/templates/delete_confirmation.pt
M plone/app/content/browser/templates/object_rename.pt
M plone/app/content/browser/templates/select_default_page.pt
M plone/app/content/browser/templates/select_default_view.pt
M plone/app/content/browser/vocabulary.py
M plone/app/content/configure.zcml
M plone/app/content/namechooser.py
M plone/app/content/testing.py
M plone/app/content/tests/profiles/non-ascii-workflow-profile/workflows.xml
M plone/app/content/tests/profiles/non-ascii-workflow-profile/workflows/non-ascii-workflow/definition.xml
M plone/app/content/tests/profiles/non-ascii-workflow.zcml
M plone/app/content/tests/test_actions.py
M plone/app/content/tests/test_adding.py
M plone/app/content/tests/test_content_status_modify.py
M plone/app/content/tests/test_contents.py
M plone/app/content/tests/test_folder.py
M plone/app/content/tests/test_namechooser_unit.py
M plone/app/content/tests/test_non_ascii_characters_in_workflow_state.py
M plone/app/content/tests/test_selectdefaultpage.py
M plone/app/content/tests/test_widgets.py
M plone/app/content/utils.py
M pyproject.toml
M setup.py
D news/266.bugfix
D news/268.bugfix
D news/3858.internal
D setup.cfg
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-10-31T22:08:10+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.content@ccc85f6

Remove deprecation warning for INameFromTitle as it breaks some use cases.

See plone/plone.app.dexterity#379 (comment)

Files changed:
A news/3858.internal
M plone/app/content/interfaces.py
D news/3858.internal.2
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-11-02T11:54:18+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.content@d487863

Merge pull request #271 from plone/use-interface-from-plone-base

Move `INameFromTitle` interface to `plone.base`

Files changed:
A news/3858.internal
M plone/app/content/interfaces.py
M plone/app/content/namechooser.py
M plone/app/content/namechooser.txt
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Nov 2, 2023
Branch: refs/heads/master
Date: 2023-10-15T17:57:43+02:00
Author: Gil Forcada Codinachs (gforcada) <gil.gnome@gmail.com>
Commit: plone/plone.app.content@85a904c

feat: deprecate INameFromTitle in this distribution

It got moved to `plone.base`.

Adds a deprecation warning so the interface can be moved right away, but
does not break other code that still imports from here, and show a
deprecation warning about it.

Files changed:
M plone/app/content/interfaces.py
M plone/app/content/namechooser.py
M plone/app/content/namechooser.txt
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-10-15T17:59:36+02:00
Author: Gil Forcada Codinachs (gforcada) <gil.gnome@gmail.com>
Commit: plone/plone.app.content@de83c82

Add news entry

Files changed:
A news/3858.internal.2
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-10-25T17:18:41+02:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.content@9a9dbf3

Merge branch 'master' into use-interface-from-plone-base

Files changed:
A .editorconfig
A .flake8
A .github/workflows/meta.yml
A .meta.toml
A .pre-commit-config.yaml
A tox.ini
M .gitignore
M CHANGES.rst
M plone/app/content/browser/actions.py
M plone/app/content/browser/configure.zcml
M plone/app/content/browser/constraintypes.pt
M plone/app/content/browser/constraintypes.py
M plone/app/content/browser/content_status_history.py
M plone/app/content/browser/contents/__init__.py
M plone/app/content/browser/contents/configure.zcml
M plone/app/content/browser/contents/copy.py
M plone/app/content/browser/contents/cut.py
M plone/app/content/browser/contents/delete.py
M plone/app/content/browser/contents/paste.py
M plone/app/content/browser/contents/properties.py
M plone/app/content/browser/contents/rename.py
M plone/app/content/browser/contents/tags.py
M plone/app/content/browser/contents/workflow.py
M plone/app/content/browser/folderfactories.pt
M plone/app/content/browser/full_review_list.pt
M plone/app/content/browser/i18n.py
M plone/app/content/browser/interfaces.py
M plone/app/content/browser/selection.py
M plone/app/content/browser/table.pt
M plone/app/content/browser/table.txt
M plone/app/content/browser/templates/content_status_history.pt
M plone/app/content/browser/templates/delete_confirmation.pt
M plone/app/content/browser/templates/object_rename.pt
M plone/app/content/browser/templates/select_default_page.pt
M plone/app/content/browser/templates/select_default_view.pt
M plone/app/content/browser/vocabulary.py
M plone/app/content/configure.zcml
M plone/app/content/namechooser.py
M plone/app/content/testing.py
M plone/app/content/tests/profiles/non-ascii-workflow-profile/workflows.xml
M plone/app/content/tests/profiles/non-ascii-workflow-profile/workflows/non-ascii-workflow/definition.xml
M plone/app/content/tests/profiles/non-ascii-workflow.zcml
M plone/app/content/tests/test_actions.py
M plone/app/content/tests/test_adding.py
M plone/app/content/tests/test_content_status_modify.py
M plone/app/content/tests/test_contents.py
M plone/app/content/tests/test_folder.py
M plone/app/content/tests/test_namechooser_unit.py
M plone/app/content/tests/test_non_ascii_characters_in_workflow_state.py
M plone/app/content/tests/test_selectdefaultpage.py
M plone/app/content/tests/test_widgets.py
M plone/app/content/utils.py
M pyproject.toml
M setup.py
D news/266.bugfix
D news/268.bugfix
D news/3858.internal
D setup.cfg
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-10-31T22:08:10+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.content@ccc85f6

Remove deprecation warning for INameFromTitle as it breaks some use cases.

See plone/plone.app.dexterity#379 (comment)

Files changed:
A news/3858.internal
M plone/app/content/interfaces.py
D news/3858.internal.2
Repository: plone.app.content

Branch: refs/heads/master
Date: 2023-11-02T11:54:18+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.content@d487863

Merge pull request #271 from plone/use-interface-from-plone-base

Move `INameFromTitle` interface to `plone.base`

Files changed:
A news/3858.internal
M plone/app/content/interfaces.py
M plone/app/content/namechooser.py
M plone/app/content/namechooser.txt
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Nov 2, 2023
Branch: refs/heads/master
Date: 2023-10-31T20:50:53+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.dexterity@e9466e8

Make the dependency on plone.app.content conditional.

This is for `INameFromTitle`, which we want to move to `plone.base`.
See plone/plone.app.dexterity#379 (comment) for why this is not working yet, and we need this workaround.

Files changed:
A news/3858.internal
M .meta.toml
M plone/app/dexterity/behaviors/configure.zcml
M pyproject.toml
M setup.py
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2023-10-31T22:17:23+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.dexterity@d4ebbe1

Test that both spellings of the plone.namefromtitle behavior work.

Both `plone.namefromtitle` and `plone.app.content.interfaces.INameFromTitle` work.
You cannot use `plone.base.interfaces.INameFromTitle` as behavior name, this was never supported.
Recommended is to use `plone.namefromtitle` in all supported Plone versions.
Using `plone.app.content.interfaces.INameFromTitle` as name will stop working in Plone 7.

Rewrote the `tests/namefromtitle.txt` doctest file as a unittest file, making it easier to test both behavior names.

Files changed:
A plone/app/dexterity/tests/test_namefromtitle.py
M plone/app/dexterity/behaviors/configure.zcml
M plone/app/dexterity/tests/test_doctests.py
D plone/app/dexterity/tests/namefromtitle.txt
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2023-11-02T11:54:24+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.dexterity@669e1e7

Merge pull request #380 from plone/maurits-plone-app-content-conditional

Make the dependency on plone.app.content conditional.

Files changed:
A news/3858.internal
A plone/app/dexterity/tests/test_namefromtitle.py
M .meta.toml
M plone/app/dexterity/behaviors/configure.zcml
M plone/app/dexterity/tests/test_doctests.py
M pyproject.toml
M setup.py
D plone/app/dexterity/tests/namefromtitle.txt
mister-roboto pushed a commit to plone/buildout.coredev that referenced this pull request Nov 2, 2023
Branch: refs/heads/master
Date: 2023-10-31T20:50:53+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.dexterity@e9466e8

Make the dependency on plone.app.content conditional.

This is for `INameFromTitle`, which we want to move to `plone.base`.
See plone/plone.app.dexterity#379 (comment) for why this is not working yet, and we need this workaround.

Files changed:
A news/3858.internal
M .meta.toml
M plone/app/dexterity/behaviors/configure.zcml
M pyproject.toml
M setup.py
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2023-10-31T22:17:23+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.dexterity@d4ebbe1

Test that both spellings of the plone.namefromtitle behavior work.

Both `plone.namefromtitle` and `plone.app.content.interfaces.INameFromTitle` work.
You cannot use `plone.base.interfaces.INameFromTitle` as behavior name, this was never supported.
Recommended is to use `plone.namefromtitle` in all supported Plone versions.
Using `plone.app.content.interfaces.INameFromTitle` as name will stop working in Plone 7.

Rewrote the `tests/namefromtitle.txt` doctest file as a unittest file, making it easier to test both behavior names.

Files changed:
A plone/app/dexterity/tests/test_namefromtitle.py
M plone/app/dexterity/behaviors/configure.zcml
M plone/app/dexterity/tests/test_doctests.py
D plone/app/dexterity/tests/namefromtitle.txt
Repository: plone.app.dexterity

Branch: refs/heads/master
Date: 2023-11-02T11:54:24+01:00
Author: Maurits van Rees (mauritsvanrees) <maurits@vanrees.org>
Commit: plone/plone.app.dexterity@669e1e7

Merge pull request #380 from plone/maurits-plone-app-content-conditional

Make the dependency on plone.app.content conditional.

Files changed:
A news/3858.internal
A plone/app/dexterity/tests/test_namefromtitle.py
M .meta.toml
M plone/app/dexterity/behaviors/configure.zcml
M plone/app/dexterity/tests/test_doctests.py
M pyproject.toml
M setup.py
D plone/app/dexterity/tests/namefromtitle.txt
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.

None yet

4 participants