@@ -93,7 +93,7 @@ class Meta:
9393 models .Index (fields = ["-created_at" ]),
9494 ]
9595
96- def save (self , * args , ** kwargs ) -> None :
96+ def save (self , * args , ** kwargs ) -> "AuthzCourseAuthoringMigrationRun" :
9797 """Enforce at most one RUNNING record per (scope_type, scope_key).
9898
9999 MySQL does not support partial unique indexes, so this check is done at
@@ -112,6 +112,7 @@ def save(self, *args, **kwargs) -> None:
112112 f"Duplicate RUNNING migration run for scope { self .scope_type } :{ self .scope_key } "
113113 )
114114 super ().save (* args , ** kwargs )
115+ return self
115116
116117 # pylint: disable=too-many-positional-arguments
117118 @classmethod
@@ -149,25 +150,25 @@ def create_skipped(
149150 extra = {** (metadata or {}), "skip_reason" : "A concurrent migration run is already active for this scope." }
150151 return cls ._create (migration_type , scope_type , scope_key , Status .SKIPPED , extra )
151152
152- def _finalize (self , status : str , metadata_updates : dict | None = None ) -> None :
153+ def _finalize (self , status : str , metadata_updates : dict | None = None ) -> "AuthzCourseAuthoringMigrationRun" :
153154 """Finalize the migration run."""
154155 self .status = status
155156 self .completed_at = timezone .now ()
156157 if metadata_updates :
157158 self .metadata = {** (self .metadata or {}), ** metadata_updates }
158- self .save (update_fields = ["status" , "completed_at" , "updated_at" , "metadata" ])
159+ return self .save (update_fields = ["status" , "completed_at" , "updated_at" , "metadata" ])
159160
160- def mark_partial_success (self , * , metadata_updates = None ) -> None :
161+ def mark_partial_success (self , * , metadata_updates = None ) -> "AuthzCourseAuthoringMigrationRun" :
161162 """Mark the migration run as partially successful."""
162- self ._finalize (Status .PARTIAL_SUCCESS , metadata_updates )
163+ return self ._finalize (Status .PARTIAL_SUCCESS , metadata_updates )
163164
164- def mark_completed (self , * , metadata_updates = None ) -> None :
165+ def mark_completed (self , * , metadata_updates = None ) -> "AuthzCourseAuthoringMigrationRun" :
165166 """Mark the migration run as completed."""
166- self ._finalize (Status .COMPLETED , metadata_updates )
167+ return self ._finalize (Status .COMPLETED , metadata_updates )
167168
168- def mark_failed (self , * , exception = None ) -> None :
169+ def mark_failed (self , * , exception = None ) -> "AuthzCourseAuthoringMigrationRun" :
169170 """Mark the migration run as failed."""
170- self ._finalize (Status .FAILED , {"error" : str (exception )} if exception is not None else None )
171+ return self ._finalize (Status .FAILED , {"error" : str (exception )} if exception is not None else None )
171172
172173 def __str__ (self ) -> str :
173174 """Return a string representation of the migration run."""
0 commit comments