Open
Description
Problem
Uploading a new file via contents doesn't handle the case where there is no primary field adapter, like .txt files
Others have encounted this problem
https://community.plone.org/t/objects-can-no-longer-adapt-to-iprimaryfieldinfo/2597/3
https://community.plone.org/t/ttw-dexterity-ct-could-not-adapt-plone-dexterity-content-container-to-interfaces-iprimaryfieldinfo/1562
Steps to reproduce
- contents > upload (in volto)
- upload .txt file
- Get exception
Expected behaviour
- Probably best idea is to fall back to File if iprimaryfieldinfo doesn't adapt. ie just always allow upload
- Alternatives
- ensure IPrimaryFieldInfo works for Page content types
- give error and ask them to configure the mine type registery
- ensure all types have a way convert from a file of any kind?
- very least get rid of the .txt files being uploaded as Page instead of File? When does that make sense?
Actual behaviour
If you upload a .txt file via x you will get the following exception
Traceback (innermost last):
Module ZPublisher.WSGIPublisher, line 167, in transaction_pubevents
Module ZPublisher.WSGIPublisher, line 376, in publish_module
Module ZPublisher.WSGIPublisher, line 271, in publish
Module ZPublisher.mapply, line 85, in mapply
Module Products.PDBDebugMode.wsgi_runcall, line 60, in pdb_runcall
Module plone.restapi.services.content.tus, line 65, in __call__
Module plone.restapi.services, line 19, in render
Module plone.restapi.services.content.tus, line 224, in reply
Module plone.restapi.services.content.tus, line 250, in create_or_modify_content
Module zope.component.hooks, line 135, in adapter_hook
Module plone.dexterity.primary, line 23, in __init__
TypeError: ('Could not adapt', <FolderishDocument at document.2023-06-16.3422935871>, <InterfaceClass plone.rfc822.interfaces.IPrimaryFieldInfo>)
This is because text/plain and .txt is linked to Page content types. and Page content types no longer seem to have a primary field that accepts text
due to this code
if not fieldname:
info = IPrimaryFieldInfo(obj, None)
if info is not None:
fieldname = info.fieldname
elif base_hasattr(obj, "getPrimaryField"):
field = obj.getPrimaryField()
fieldname = field.getName()
Alternative would be to give a helpful error that the content type registry needs to adjusted to pick a better content type.