This needs some more testing, but I was able to override validation (or any other function relevant at validation time) by introducing a new hook called “before_validate” to document.py.
## Two new lines added to document.py in run_before_save_methods
def run_before_save_methods(self):
"""Run standard methods before `INSERT` or `UPDATE`. Standard Methods are:
- `validate`, `before_save` for **Save**.
- `validate`, `before_submit` for **Submit**.
- `before_cancel` for **Cancel**
- `before_update_after_submit` for **Update after Submit**
Will also update title_field if set"""
self.load_doc_before_save()
self.reset_seen()
if self.flags.ignore_validate:
return
if self._action=="save":
self.run_method("before_validate") # new line
self.run_method("validate")
self.run_method("before_save")
elif self._action=="submit":
self.run_method("before_validate") # new line
self.run_method("validate")
self.run_method("before_submit")
elif self._action=="cancel":
self.run_method("before_cancel")
elif self._action=="update_after_submit":
self.run_method("before_update_after_submit")
self.set_title_field()
I can get this posted as a pull request, but since it’s a relatively low-level function I thought it would be better to post it here first. Is there anything I am neglecting in this approach? It seems to work fine with no obvious performance implications.