plone / plone/plone.api

Cannot create an object with a custom naming behavior

Open
#362 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
101
Forks
62
Avg merge
15h 15m
Merged PRs (30d)
1

Description

Because of these lines:

        derived_id = id or title
        new_id = chooser.chooseName(derived_id, content)

in https://github.com/plone/plone.api/blob/d65c81e6eeb69f0a581fa50e9f0500372efe45b5/src/plone/api/content.py#L115

I will never reach line 34 (nameFromTitle = INameFromTitle(obj, None)) here
https://github.com/plone/plone.app.content/blob/9c220b2ceace9c74a464529d89e4a66c16c0fc17/plone/app/content/namechooser.py#L34

For this reason it is not possible to create with plone.api an object that authomatically gets the id correctly from a custom INameFromTitle behavior that is not based on the title.

I noticed this with a custom INameFromTitle adapter that gives an id based on the date, but I think this is an issue also for the File content type (which uses this behavior: https://github.com/plone/plone.app.dexterity/blob/184184150ab6b7743769fe92bf8ec78e5fb52873/plone/app/dexterity/behaviors/filename.py#L16)

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start in plone.api/src/plone/api/content.py around the derived_id and chooser.chooseName calls, then compare it with plone.app.content/namechooser.py at line 34 and the filename behavior referenced in plone.app.dexterity. Trace how custom INameFromTitle adapters are selected during creation. Done means plone.api can create objects whose id is supplied by a custom naming behavior, including the reported File case.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.