Error handling

Trigger Log

Heroku Connect uses the Trigger Log to track changes to connected model instances, as well as its own efforts to sync them to Salesforce.

django-heroku-connect exposes the trigger log tables, which are managed by Heroku Connect, as Django models TriggerLog and TriggerLogArchive. These models also offer access to database stored procedures provided by Heroku Connect to fix sync errors.

See also

TriggerLogAbstract for how to use trigger log models.

Admin actions

The admins for the trigger log models (discussed below) offer actions to ignore or retry failed trigger log entries. The former simply sets the state of the entry to IGNORED, if you want to clean up for whatever reason.

Retrying means an attempt to re-sync the change represented by the trigger log. This entails creating an identical trigger log row in NEW state, either by simply changing the failed row’s state (TriggerLog), or by copying an archived row back into the live TriggerLog and setting the archived state to REQUEUED (TriggerLogArchive). Heroku Connect will then normally process that row.

If this simple attempt at a fix does not work, try to manually call capture_insert() or capture_update() on a failed trigger log instance.

Models

heroku_connect.models.TRIGGER_LOG_ACTION = {'DELETE': 'DELETE', 'INSERT': 'INSERT', 'UPDATE': 'UPDATE'}[source]

The type of change that a trigger log object represents.

heroku_connect.models.TRIGGER_LOG_STATE = {'FAILED': 'FAILED', 'IGNORE': 'IGNORE', 'IGNORED': 'IGNORED', 'MERGED': 'MERGED', 'NEW': 'NEW', 'PENDING': 'PENDING', 'READONLY': 'READONLY', 'REQUEUE': 'REQUEUE', 'REQUEUED': 'REQUEUED', 'SUCCESS': 'SUCCESS'}[source]

The sync state of the change tracked by a trigger log entry.

class heroku_connect.models.TriggerLog(*args, **kwargs)[source]

Represents entries in the Heroku Connect trigger log.

exception DoesNotExist[source]
exception MultipleObjectsReturned[source]
redo()[source]

Re-sync the change recorded in this trigger log.

This MAY create new TriggerLog instances, or save changes to this instance.

Returns:

A TriggerLog instance that represents the re-application; possibly self.

class heroku_connect.models.TriggerLogAbstract(*args, **kwargs)[source]

Support for accessing the Heroku Connect Trigger Log data and related actions.

Heroku Connect uses a Trigger Log table to track local changes to connected models (that is, in the Heroku database. Such changes are recorded as rows in the trigger log and, for read-write mappings, eventually written back to Salesforce.

Old logs are moved to an archive table (after being processed), from where they are purged eventually (currently 30 days for paid plans, 7 days for demo). Recent logs are modeled by TriggerLog; archived logs by TriggerLogArchive.

The data represented by these models is maintained entirely by Heroku Connect, and is instrumental to its operations; it should therefore not be modified. A possible exception is the state field, which may be changed as detailed in the error handling section in the Heroku Connect documentation.

capture_insert(*, exclude_fields=())[source]

Apply TriggerLogAbstract.capture_insert_from_model() for this log.

classmethod capture_insert_from_model(table_name, record_id, *, exclude_fields=())[source]

Create a fresh insert record from the current model state in the database.

For read-write connected models, this will lead to the attempted creation of a corresponding object in Salesforce.

Parameters:
  • table_name (str) – The name of the table backing the connected model (without schema)

  • record_id (int) – The primary id of the connected model

  • exclude_fields (Iterable[str]) – The names of fields that will not be included in the write record

Returns:

A list of the created TriggerLog entries (usually one).

Raises:

LookupError – if table_name does not belong to a connected model

capture_update(*, update_fields=(), update_columns=())[source]

Apply TriggerLogAbstract.capture_insert_from_model() for this log.

classmethod capture_update_from_model(table_name, record_id, *, update_fields=(), update_columns=())[source]

Create a fresh update record from the current model state in the database.

For read-write connected models, this will lead to the attempted update of the values of a corresponding object in Salesforce.

Parameters:
  • table_name (str) – The name of the table backing the connected model (without schema)

  • record_id (int) – The primary id of the connected model

  • update_fields (Iterable[str]) – If given, the names of fields that will be included in the write record. These will be converted into database column names.

  • update_columns (Iterable[str]) – If given, the names of database column names that will be included in the write record.

Returns:

A list of the created TriggerLog entries (usually one).

Raises:

LookupError – if table_name does not belong to a connected model

get_model()[source]

Fetch the instance of the connected model referenced by this log record.

Returns:

The connected instance, or None if it does not exists.

related(*, exclude_self=False)[source]

Get a QuerySet for all trigger log objects for the same connected model.

Parameters:

exclude_self (bool) – Whether to exclude this log object from the result list

class heroku_connect.models.TriggerLogArchive(*args, **kwargs)[source]

Represents entries in the Heroku Connect trigger log archive.

exception DoesNotExist[source]
exception MultipleObjectsReturned[source]
redo()[source]

Re-sync the change recorded in this trigger log.

Creates a NEW live trigger log from the data in this archived trigger log and sets the state of this archived instance to REQUEUED.

Returns:

The TriggerLog instance that was created from the data of this archived log.

class heroku_connect.models.TriggerLogQuerySet(model=None, query=None, using=None, hints=None)[source]

A QuerySet for trigger log models.

failed()[source]

Filter for log records with sync failures.

related_to(instance)[source]

Filter for all log objects of the same connected model as the given instance.