Open sergei-maertens opened 4 years ago
/cc @damm89
Building on our slack conversation:
Digging into the DRF serializers' validation functions for the email task I came across this stackoverflow topic that helps you quickly get a clear overview of the timing of the called functions once is_valid is called on a DRF Serializer object:
In the case of the email task it was desirable for the serializer to raise a MissingVariable error in line with expectations for the camunda incident console if a required variable was missing, empty or invalid. Using the marvelous overview seen above, two strategies quickly became apparent:
- Do a custom validation right as the is_valid function is called, before you call the is_valid function from the DRF serializer object. (preferred)
- Let the DRF is_valid function run its course and catch the error and depending on the ValidationError code from DRF, insert the error detail into the MissingVariable exception. (not preferred)
In line with 1) I suggest making a custom serializer object for bptl tasks that does precisely that. A first iteration of a simple/naive suggested implementation:
class BPTLSerializer(serializers.Serializer):
def call_bptl_task_validation(self, raise_exception):
self.errors = somecode1
valid = somecode2
if raise_exception:
raise SomeBPTLException(message)
return valid
def is_valid(self, raise_exception=False):
valid = self.call_bptl_task_validation(raise_exception=raise_exception)
return valid and super().is_valid()
Additional reason to do this - we get input variables that should point to a document type in the catalogi API, but we find out that the configured URL was wrong way too late in the process (after Xential callback happened).
We want to error sooner, which we can do by a better task variable validation system.
Variables are more often structured than not (simple primitive strings/numbers vs. JSON objects), which can/should be validated using DRF serializers or an implementation on top of that.
It's important that:
Probably a 1.1.0 feature, wouldn't let this block a 1.0 release.