Validation for DB model objects representing job params
In our job parameters model (OqJobProfile in code, uiapi.oq_
parameters. The need for a robust and complete validation facility should be obvious.
The patterns we put in place with respect to the job profile validation could be extended to other models as well. At the moment, however, the urgency lies solely in validating the job parameter model.
After having a short technical discussion, here's what we came up with.
--Types of Validation--
We are breaking the concept of validation into two categories:
- Simple validation
Examples:
- imt (intensity measure type) should be one of (pga, sa, pgv, pgd, ia, rsd, mmi)
- investigation_time should be > 0.0
- Context-sensitive validation
Examples:
- if imt is 'sa': period and damping must be defined; else, period and damping can/should be null
- if calculation_mode is 'uhs': imt must default to 'sa', period can/should be null, damping must be defined, and uhs_periods must be defined
--Implementation of Validation--
As noted above, simple validation rules apply to the value of a single field. One way to implement this would be to define validators (where required) for each field in the Django model class. More about model field validators: https:/
Blueprint information
- Status:
- Not started
- Approver:
- None
- Priority:
- Undefined
- Drafter:
- None
- Direction:
- Needs approval
- Assignee:
- None
- Definition:
- New
- Series goal:
- None
- Implementation:
- Unknown
- Milestone target:
- None
- Started by
- Completed by