wuttasync.importing.versions

Importing Versions

This is a special type of import, only relevant when data versioning is enabled.

See the handler class for more info: FromWuttaToVersions

class wuttasync.importing.versions.FromWuttaToVersionBase(config, **kwargs)[source]

Base importer class for Wutta -> Versions.

This imports from FromWuttaMirror and ToWutta.

The import handler will dynamically generate importers using this base class; see make_importer_factory().

continuum_txn = None

Reference to the handler’s attribute of the same name: continuum_txn

This is the SQLAlchemy-Continuum transaction record, to which any new version records will associate (if needed).

This transaction will track the effective user responsible for the change(s), their client IP, and timestamp.

get_target_query(source_data=None)[source]

This modifies the normal query to ensure we only get the “latest valid” version for each record, for comparison to source.

Note

In some cases, it still may be possible for multiple “latest” versions to match for a given record. This means inconsistent data; a warning should be logged if so, and you must track it down…

See also docs for parent method: get_target_query()

class wuttasync.importing.versions.FromWuttaToVersions(config, **kwargs)[source]

Handler for Wutta -> Versions import.

The purpose of this is to ensure version tables accurately reflect the current “live” data set, for given table(s). It is only relevant/usable if versioning is configured and enabled. For more on that see Wutta-Continuum.

For a given import model, the source is the “live” table, target is the “version” table - both in the same app database.

When reading data from the target side, it only grabs the “latest” (valid) version record for each comparison to source.

When changes are needed, instead of updating the existing version record, it always writes a new version record.

This handler will dynamically create importers for all versioned models in the app model; see make_importer_factory().

begin_target_transaction()[source]

In addition to normal logic, this does some setup for SQLAlchemy-Continuum:

It establishes a “unit of work” by calling unit_of_work(), assigning the result to continuum_uow.

It then calls create_transaction() and assigns that to continuum_txn.

It also sets the comment for the transaction, if applicable.

See also docs for parent method: begin_target_transaction()

continuum_txn = None

Reference to the SQLAlchemy-Continuum transaction record, to which any new version records will associate (if needed).

This transaction will track the effective user responsible for the change(s), their client IP, and timestamp.

This reference is passed along to the importers as well (as continuum_txn) via get_importer_kwargs().

See also continuum_uow.

continuum_uow = None

Reference to the sqlalchemy-continuum:`sqlalchemy_continuum.UnitOfWork created (by the SQLAlchemy-Continuum versioning_manager) when the transaction begins.

See also continuum_txn and begin_target_transaction().

define_importers()[source]

This overrides typical (manual) importer definition, instead generating importers for all versioned models.

It will inspect the app model and call make_importer_factory() for each model found, keeping only the valid importers.

See also the docs for parent method: define_importers()

get_importer_kwargs(key, **kwargs)[source]

This modifies the new importer kwargs to add:

See also docs for parent method: get_importer_kwargs()

make_importer_factory(model_class, name)[source]

Try to generate a new importer class for the given data model. This is called by define_importers().

If the provided model_class is not versioned, this will fail and return None.

For a versioned model, the new importer class will inherit from FromWuttaToVersionBase.

Its (target) model_class will be set to the version model.

Its source_model_class will be set to the normal model.

Parameters:
  • model_class – A (normal, not version) data model class.

  • name – The “model name” for the importer. New class name will be based on this, so e.g. Widget model name becomes WidgetImporter class name.

Returns:

The new class, or None

target_key = 'versions'