class modularodm.storedobject.StoredObject(**kwargs)[source]

Base class to be used for models.

get_changed_fields(cached_data, storage_data)[source]

Get fields that differ between the cache_sandbox and the current object. Validation and after_save methods should only be run on diffed fields.

  • cached_data – Storage-formatted data from cache_sandbox
  • storage_data – Storage-formatted data from object

List of diffed fields

classmethod load(*args, **kwargs)[source]

Get a record by its primary key.

classmethod migrate_all()[source]

Migrate all records in this collection.

classmethod migrate(old, new, verbose=True, dry_run=False, rm_refs=True)[source]

Migrate record to new schema.

  • old – Record from original schema
  • new – Record from new schema
  • verbose – Print detailed info
  • dry_run – Dry run; make no changes if true
  • rm_refs – Remove references on deleted fields

Apply record-level validation. Run on save.

save(*args, **kwargs)[source]

Save a record.

Parameters:force (bool) – Save even if no fields have changed; used to update back-references
Returns:List of changed fields

Update multiple fields, specified by keyword arguments.


person.update(given_name='Fred', family_name='Mercury')

... is equivalent to ...

person.given_name = 'Fred'
person.family_name = 'Mercury'

field names and the values to set

classmethod find(*args, **kwargs)[source]
  • query
  • kwargs

an iterable of StoredObject instances

classmethod delegate(method, conflict=None, *args, **kwargs)[source]

Execute or queue a database action. Variable positional and keyword arguments are passed to the provided method.

  • method (function) – Method to execute or queue
  • conflict (bool) – Potential conflict between cache_sandbox and backend, e.g., in the event of bulk updates or removes that bypass the cache_sandbox
classmethod start_queue()[source]

Start the queue. Between calling start_queue and commit_queue, all writes will be deferred to the queue.

classmethod clear_queue()[source]

Clear the queue.

classmethod cancel_queue()[source]

Cancel any pending actions. This method clears the queue and also clears caches if any actions are pending.

classmethod commit_queue()[source]

Commit all queued actions. If any actions fail, clear caches. Note: the queue will be cleared whether an error is raised or not.

classmethod subscribe(signal_name, weak=True)[source]
  • signal_name (str) – Name of signal to subscribe to; must be found in
  • weak (bool) – Create weak reference to callback

Decorator created by Signal::connect_via


ValueError if signal is not found

Example usage:

>>> @Schema.subscribe('before_save')
... def listener(cls, instance):
...     instance.value += 1
classmethod remove_one(*args, **kwargs)[source]

Remove an object, along with its references and back-references. Remove the object from the cache_sandbox and sets its _detached flag to True.

  • which – Object selector: Query, StoredObject, or primary key
  • rm – Remove data from backend
classmethod remove(*args, **kwargs)[source]

Remove objects by query.

Parameters:query – Query object