Great Expectations - Adding custom action to ephemeral data context

97 Views Asked by At

I am trying to pass a custom action to Great Expectations, i.e. a class implementing the ValidationAction interface:

from great_expectations.checkpoint.actions import ValidationAction

class StoreValidationResultsToDeltaAction(ValidationAction):
    def __init__(self, att):
        self.att = att

    def _run(self, validation_result_suite, *args, **kwargs):
       ... # implementation

Normally if I use a FileDataContext I would just place this in a .py file under gx/plugins/<folder> and then when running the validation the action is loaded at runtime and executed.

I was hoping to do the same using an EphemeralDataContext:

data_context_config = DataContextConfig(
    store_backend_defaults=InMemoryStoreBackendDefaults(),
    plugins_directory="<path_to_plugins_folder_containing_action_class>"
)
gx_context = gx.get_context(project_config=data_context_config)

However it does not seem to work. Any idea how to achieve this?

1

There are 1 best solutions below

0
someguy89 On

I had the same issue, solved by simply pointing at the package where the custom action was implemented:

import pkg_resources

data_context_config = DataContextConfig(
    store_backend_defaults=InMemoryStoreBackendDefaults(),
    plugins_directory=pkg_resources.resource_filename(__package__, "plugins")
)
gx_context = gx.get_context(project_config=data_context_config)

For me, the plugins package is a subpackage of the one containing the code mentioned above, you'll probably have to change it to something else. As regards the custom action, that's a sample of how I specified it in checkpoint:

context.add_or_update_checkpoint(
    ...,
    action_list=Checkpoint.DEFAULT_ACTION_LIST + ({"name": "some_custom_action", "action": {"class_name": "CustomAction", "module_name": "actions"}},),
)

Again, you'll have to change class_name and module_name values, then it should be good to go!