Setting text field in create fails on Dexterity
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 101
- Forks
- 62
- Avg merge
- 15h 15m
- Merged PRs (30d)
- 1
Description
The following code fails on Dexterity-based content types (plone.app.contenttypes):
with api.env.adopt_roles(['Manager']):
obj = api.content.create(
container=portal,
type='Document',
title=u'Pangram',
text=u'<p>The quick brown fox jumps over the lazy dog</p>',
)
on Archetypes, the text field is set; on Dexterity, the text field is set as a unicode object leading to the following error:
AttributeError: 'unicode' object has no attribute 'output_relative_to'
the workaround is something like:
def set_text_field(obj, text):
try:
obj.setText(text) # Archetypes
except AttributeError:
obj.text = RichTextValue(text, 'text/html', 'text/html') # Dexterity
where do we handle this? here or in plone.app.contenttypes?
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by inspecting api.content.create and how it sets fields for Archetypes versus Dexterity-based types from plone.app.contenttypes. Reproduce the issue with the provided Document example and compare it with the setText and RichTextValue workaround. Done means creating the Document with text no longer leaves a raw unicode value that raises output_relative_to.
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