Let creatorsDefault return None for anonymous user (fixes plone/plone.app.vocabularies/issues/59) #311
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This would fix plone/plone.app.vocabularies#59, but I'm only floating this change as an idea, hoping for some feedback.
z3c.form.widget.Widget.update()
passes the result ofcreatorsDefault
(which is called by anIValue
adapter'sget()
method) toplone.app.z3cform.converters.AjaxSelectWidgetConverter.toWidgetValue()
.getSecurityManager().getUser()
returns a regular<PropertiedUser>
for most requests and thus the return value is a tuple, e.g.('admin',)
.However, for ajax requests, e.g.
/++add++MyContentType/++widget++form.widgets.IMyBehavior.behavior_field
, the user is anonymous:Thus, the return value is the tuple
(None,)
. This breaksAjaxSelectWidgets
when the content type includes the Dublin Core behavior or just the ownership field, even though the field itself is aRelationList
with avalue_type=RelationChoice( source=CatalogSource(portal_type='MyContentType) )
. In other words, even though the broken field has no need for the item's creator, the creator gets calculated anyway when the request is handled.The problem with the tuple
(None,)
is thattoWidgetValue()
does not know how to deal with it and so it returnsNone
instead offield.missing_value
as it should.This could be fixed in at least four different places:
None
for anonymous users would make any other code mad.(None,)
tuple instead ofNone
, so this could be fixed by simply adding a check for(None,)
.(None,)
toNone
before passing it on.I'll add tests and changelog, etc if this is the way to go.