Hooks

hook_data_validation

class hooks.data_validation.AbstractDataValidationHook(parent)[source]

Bases: Hook

Abstract hook class that defines the necessary methods for the Data Validation App to function.

This is the main hook for the App and is essential for the App to display the validation data and to apply any validation actions to the DCC data. In this hook, define the data validation rules, and check and fix functionality for a specific DCC.

This hook does not define any of the validation data or implement the methods itself, since the data to be validated will be specific to the running DCC. This hook class must be subclassed, for example, by the engine where DCC specific functionality is available.

get_validation_data()[source]

Return the main data validation rule set that drives the App.

This method must be implemented by the subclass.

It is not enforced, but the dictionary returned by this function should be formated such that each key-value pair can be passed to create a tk_multi_data_validation.api.data.ValidationRule.

Returns:

The validation data that can be used to validate the data.

Return type:

dict

Raises:

NotImplementedError – If the subclass does not implement this function.

sanitize_check_result(errors)[source]

Sanitize the value returned by any validate function to conform to the standard format.

This method must be implemented by the subclass.

Each engine will provide their own validation functions which should return the list of objects that do not follow the validation rule. These objects will be referred to as “errors”. In order for the Data Validation App to handle these objects coming from different DCCs, the error objects need to be sanitized into a format that the Data Validation App can handle. The standard format that the Data Validation App excepts is a list of dictionaries, where each dictionary defines a DCC error object with the following keys:

is_valid:

bool True if the validate function succeed with the current data, else False.

errors:

List[dict] The list of error objects (found by the validate function). None or empty list if the current data is valid. List elements have the following keys:

id:

str | int A unique identifier for the error object.

name:

str The display name for the error object.

type:

str The display name of the error object type (optional).

This method will be called by the Data Validation App after any validate function is called, in order to receive the validate result in the required format.

Parameters:

errors (any) – The value returned by a validate function that needs to be sanitized to the standard format.

Returns:

The validation result in the standardized format.

Return type:

dict

resolve_rules(manager, rules)[source]

Helper method to execute the manager resolve rule and then call validate post resolution.

Parameters:
  • manager (<ValidationManager>) – Data validation manager

  • rules (list<ValidationRule>) – The list of rules to resolve and then validate.

resolve_all_rules(manager, rules)[source]

Helper method to execute the manager resolve rule for all the rules.

Parameters:
  • manager (<ValidationManager>) – Data validation manager

  • rules (list<ValidationRule>) – The list of rules to resolve.

post_fix_action(rules)[source]

Helper method to execute post fix actions once all the rules have been resolved

Parameters:

rules (list<ValidationRule>) – The list of rules to resolve.