API Reference

management commands

validate

./manage.py validate [LABELS]

run the data validation.

LABELS – an (optional) space seperated list of labels of the form <app_label>, <app_label>.<model_name>, or <app_label>.<model_name>::<validator_name>. If no labels are provided then all models are validated.

datavalidation

data_validation.data_validator(select_related=None, prefetch_related=None)

A decorator that identifies a method on a django model as a data validator. The decorated method may be a regular (instance) method or a @classmethod on a django model. It must take only one parameter (self or cls) and return a validation result. See Writing Data Validators for examples.

Parameters
  • select_related (Union[None,str,List[str]]) – arguments to be passed to QuerySet.select_related

  • prefetch_related (Union[None,str,List[str]]) – arguments to be passed to QuerySet.prefetch_related

Returns

a function

class data_validation.NA
class data_validation.PASS
class data_validation.FAIL

values to be returned from data validators to signify Not Applicable, Passing, or Failing respectively.

Parameters
  • comment (str) – (FAIL only) an optional comment to return. You can also pass comments to PASS and NA but such objects are not stored to the database so the comment is discarded.

  • allowed_to_fail (bool) – (FAIL only) if an object fails validation but it is allowed or expected to fail then you can pass FAIL(allowed_to_fail=True). A validator will not be considered to have failed if any objects that fail are marked allowed_to_fail.

class data_validation.Summary

A possible return value for a class method validator

Parameters
  • num_na (int) – the number of objects for which validation is not applicable

  • num_passing (int) – the number of objects that pass validation

  • failures (Union[QuerySet,List[models.Model],List[int]]) – a QuerySet, list of objects or their ids that fail validation. See Writing Data Validators for examples.

enum Status

An Enum representing the validation status of a validator, model, or app

enumerator UNINITIALIZED
enumerator PASSING
enumerator FAILING
enumerator EXCEPTION
enumerator WARNING

datavalidation.admin

class data_validation.admin.DataValidationMixin

Adds validation results to the django admin. See Setting up the Admin for details.

datavalidation.config

class data_validation.admin.Config

Configuration options for data validation

exclude: bool

if True, the model will be excluded from data validation. You might want this if the model is a non-abstract base model in an inheritance hierarchy.

datavalidation.models

class data_validation.models.DataValidaitonMixin

Provides methods to a django model to query the objects that fail data validation

property datavalidaiton_results
Returns

the QuerySet objects that failed data validation. The QuerySet model is of type data_validation.models.FailingObject

property datavalidation_passing
Returns

True if no objects fail validation (except those marked allowed to fail)

classmethod datavalidation_status()
Returns

the data_validaiton.results.Status of the model

datavalidation.runners

class data_validation.runners.ModelValidationRunner(model[, method_names=None])

Run all or a subset of data_validators for the given model

Parameters
  • model (Type[django.db.models.Model]) – the model to validate

  • method_names (Optional[List[str]]) – the names of the data_validators to run. If None it will run all validators on the model

run([show_progress=False])

start the validation runner

Parameters

show_progress (bool) – if True a progress bar will be displayed.

class data_validation.runners.ObjectValidationRunner(obj)

Run all instance methods data_validators for a given object. (see Writing Data Validators for the destinction on instance and class method validators)

Parameters

obj (django.db.models.Model) – the object to validate

run()

start the validation runner