Skip to content

Latest commit

 

History

History
123 lines (92 loc) · 5.58 KB

import_workflow.rst

File metadata and controls

123 lines (92 loc) · 5.58 KB

Import workflow

This document describes the import data workflow in detail, with hooks that enable customization of the import process.

Methods highlighted in yellow in the sequence diagram indicate public methods which can be overridden.

Import workflow sequence diagram

The :meth:`~import_export.resources.Resource.import_data` method of :class:`~import_export.resources.Resource` is responsible for importing data from a given dataset. Refer to the method documentation for parameters to this method.

This is what happens when the method is invoked:

  1. First, a new :class:`~import_export.results.Result` instance, which holds errors and other information gathered during the import, is initialized.

    Then, an :class:`~import_export.instance_loaders.BaseInstanceLoader` responsible for loading existing instances is initialized. A different :class:`~import_export.instance_loaders.BaseInstanceLoader` can be specified via :class:`~import_export.options.ResourceOptions`'s instance_loader_class attribute. A :class:`~import_export.instance_loaders.CachedInstanceLoader` can be used to reduce number of database queries. See the :mod:`~import_export.instance_loaders` for available implementations.

  2. The :meth:`~import_export.resources.Resource.before_import` hook is called. By implementing this method in your resource, you can customize the import process.

  3. Each row of the to-be-imported dataset is processed according to the following steps:

  4. The :class:`~import_export.results.Result` is returned.

Transaction support

If transaction support is enabled, whole import process is wrapped inside transaction and rolled back or committed respectively. All methods called from inside of :meth:`~import_export.resources.Resource.import_data` (create / delete / update) receive False for dry_run argument.