no allowable_content_types for description (avoid validation) #63
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.
Product.Archetypes.Field.validate
invokesvalidate_content_types
ifallowable_content_types
is set on a field. In case of the description field, this can lead to surprising validation results because the method is trying to guess the content type using themimetypes_registry
. Example: If you enter the word 'Stammdaten' (german for master data) as the first word into a description field, you see a validation error telling you that the MIME type 'video/quicktime' is not allowed for the field. This is because themimetypes_registry
is trying to guess the MIME type of the string 'Stammdaten' using a test inProducts.MimetypesRegistry.mime_types.magic
. The term 'Stammdaten' matches the following test pattern:[4, 'string', '=', 'mdat', 'video/quicktime']
(letters 'mdat' starting at position4)
It is perfectly valid to have 'Stammdaten' as the first term in a german description, but Plone doesn't let you save this. Looking at the other test patterns there are potentially many more cases like this.
The testing procedure maybe could be improved (validating the content type is not about guessing the MIME type from the content but rather testing wether the content conforms to one of the allowable content types) but the suggestion is to simply drop the constraint on the description field since text/plain is the fallback.