Skip to content

Commit

Permalink
Validation is also bypassed for field using a source attribute beca…
Browse files Browse the repository at this point in the history
…use it fails for now...
  • Loading branch information
gbastien committed Oct 15, 2018
1 parent cc6816b commit 1897d1a
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
3 changes: 2 additions & 1 deletion CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ Changelog
- Added methods content.uuidsToCatalogBrains and content.uuidsToObjects.
[gbastien]
- Adapted `content.validate_fields` to bypass validation when field.required=False,
value is None and field type is other than Bool.
value is None and field type is other than Bool. Validation is also bypassed for
field using a `source` attribute because it fails for now...
[gbastien]
- Added parameter raise_on_errors to content.validate_fields to raise a ValueError
when errors are found instead simply returning it.
Expand Down
7 changes: 7 additions & 0 deletions src/imio/helpers/content.py
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,13 @@ def validate_fields(obj, behaviors=True, raise_on_errors=False):
# accept None for most of fields if required=False
if value is None and not field.required and not (isinstance(field, (Bool, ))):
continue
# we sadly have to bypass validation for field having a source as it fails
# because in plone.formwidget.contenttree source.py
# self._getBrainByToken('/'.join(value.getPhysicalPath()))
# raises 'RelationValue' object has no attribute 'getPhysicalPath'
if hasattr(field, 'source') and field.source is not None:
logger.warn("Bypassing validation of field '%s'" % field)
continue
try:
field._validate(value)
except Exception, exc:
Expand Down

0 comments on commit 1897d1a

Please sign in to comment.