Skip to content

Align course model pre_save logic with awareness of deserialization #14130

@bjester

Description

@bjester

This issue is not open for contribution. Visit Contributing guidelines to learn about the contributing process and how to find suitable issues.

Current behavior

Currently, there's some logic in some of the pre_save methods on the following models, which attempts to ensure that the user fields are set under specific circumstances:

  • CourseSession.created_by_id
  • CourseSessionAssignment.assigned_by_id
  • UnitTestAssignment.activated_by_id

The logic is the form of if self._state.adding and self.assigned_by is None which ensures the ID is set when the model is added. The logic is made more complicated by the behavior expected in those models' deserialize method (ref)

When Morango deserializes a model, it passes update_dirty_bit_to=False to the model's save method. This is because the dirty bit tracks whether the model's data is updated with respect to the data serialized in the morango store.

Desired behavior

The above behavior can be further restricted by using information that is made available when Morango deserializes a model.

  • The AbstractFacilityDataModel model should be updated to pass the same arguments given to save to pre_save
  • All descendants of the above model should be updated to ensure they are at least passive to arguments being passed to pre_save
  • The current behavior referenced above, in the course models, should be updated to check whether update_dirty_bit_to=False was passed to pre_save (and hence save) and if so, allow the user ID fields to be null. Otherwise, it should enforce those as not nullable.

Notes

  • This is marked as a P1 because I'm unsure whether the existing logic is incompatible with syncing. If it is, then this should be promoted to a P0.

Value add

Better aligns the logic to the conditions under which the fields could be null, and is more restrictive in that sense than the current logic, which protects data integrity.

Possible tradeoffs

I'm fairly sure that the current behavior will not work appropriately during syncing, since the initial sync should still result in self._state.adding being True during deserialization.

Metadata

Metadata

Assignees

Labels

DEV: backendPython, databases, networking, filesystem...P1 - importantPriority: High impact on UX

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions