Princeton-LSI-ResearchComputing / tracebase

Mouse Metabolite Tracing Data Repository for the Rabinowitz Lab
MIT License
4 stars 1 forks source link

Replace all the cached fields with MaintainedModel fields #460

Open lparsons opened 2 years ago

lparsons commented 2 years ago

FEATURE REQUEST

Inspiration

Cached fields/model properties are not searchable, but the new MaintainedModel paradigm solves the same problem: it keeps fields updated when changes are made to records in related tables, and it uses real fields that are searchable.

Description

Replace all the cached fields with MaintainedModel fields. This will require modification to how MaintainedModel propagates changes. The existing case only changes from the initially changed record upward (names in TracerLabel->Tracer->Infusate). New requirements will involve downward propagation and Models without maintained fields that must pass changes up or down.

Alternatives

none

Dependencies

This issue cannot be started until the completion of the following issue(s):

Comment

C. It just occurred to me that we could make num_tracers a maintained field. Perhaps a new issue?

_Originally posted by @hepcat72 in https://github.com/Princeton-LSI-ResearchComputing/tracebase/pull/453#discussion_r905359660_


ISSUE OWNER SECTION

Assumptions

Requirements

Limitations

Affected Components

DESIGN

Interface Change description

None

Code Change Description

The existing MaintainedModel code only propagates updates to parent records when a particular update to a model object is made, however, with FCirc.is_last_serum_peak_group, FCirc does not have a child record reference and additions of peakgroups to other serum samples, or additions of serum samples themselves, would necessitate changes to sibling and/or nephew records, so changes need to be able to be propagated to child records. I implemented this in such a way that if the decorator has child fields supplied to it, changes will propagate to children first (dfs) and then up to parents. Loops are prevented by passing along an updated reference that contains record signatures.

Tests

  1. [unnecessary] Related records are updated
  2. [existing tests] Updates of Infusate.name, Tracer.name, and TracerLabel.name still work and update from changed record upward
  3. Updates of FCirc.is_last, Sample.is_serum_sample, and Animal.last_serum_sample are triggered by themselves and by changes to models down to PeakGroup.
    1. Create a new serum sample whose time collected is later than existing serum samples.
      • [x] 1. Confirm all FCirc.is_last values are unchanged.
      • [x] 2. Confirm the new sample's Sample.is_serum_sample is True.
      • [x] 3. Confirm Animal.last_serum_sample points to the new sample.
    2. Create a new msrun whose date is later than the msrun of the new serum sample (created above), a new tracer peak group in the new serum sample (created above), and related peak group labels.
      • [x] 1. Confirm all FCirc.is_last values related to the old serum sample are now false.
      • [x] 2. Create new FCirc records for the new serum sample, tracer, and label(s); and confirm each record's FCirc.is_last is true.
      • [x] 4. Add a confirmation to the above tests that there exists no maintained_field_function decorator applied to PeakGroup
  4. [unnecessary] Ability to apply multiple propagate-only decorators with different propagation patterns and different labels
hepcat72 commented 2 years ago

ToDo:

hepcat72 commented 2 years ago

It would probably be good to suspend cache updates (and access) during the propagation of maintained model updates, though I'm not sure how best to do that without making MaintainedModel dependent on HierCachedModel... I may be able to manually suspend cache activities in each maintained_field_function, but since the goal is to replace all those cached fields with actual fields, that would be somewhat of a waste of time... I'll just punt on this.