Skip to content

Commit 3d70c87

Browse files
committed
feat: Remove DiffSyncModel.diffsync field
- Remove DiffSyncModel.diffsync field - Add diffsync parameter to DiffSyncModel.create/update/delete This closes networktocode#256
1 parent b6792f5 commit 3d70c87

File tree

1 file changed

+6
-9
lines changed

1 file changed

+6
-9
lines changed

diffsync/__init__.py

+6-9
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,6 @@ class DiffSyncModel(BaseModel):
9191
Can be set as a class attribute or an instance attribute as needed.
9292
"""
9393

94-
diffsync: Optional["Adapter"] = None
95-
"""Optional: the DiffSync instance that owns this model instance."""
96-
9794
_status: DiffSyncStatus = PrivateAttr(DiffSyncStatus.SUCCESS)
9895
"""Status of the last attempt at creating/updating/deleting this model."""
9996

@@ -216,7 +213,7 @@ def create(cls, diffsync: "Adapter", ids: Dict, attrs: Dict) -> Optional[Self]:
216213
"""
217214
return cls.create_base(diffsync=diffsync, ids=ids, attrs=attrs)
218215

219-
def update_base(self, attrs: Dict) -> Optional[Self]:
216+
def update_base(self, diffsync: "Adapter", attrs: Dict) -> Optional[Self]:
220217
"""Base Update method to update the attributes of this instance, along with any platform-specific data updates.
221218
222219
This method is not meant to be subclassed, users should redefine update() instead.
@@ -234,7 +231,7 @@ def update_base(self, attrs: Dict) -> Optional[Self]:
234231
self.set_status(DiffSyncStatus.SUCCESS, "Updated successfully")
235232
return self
236233

237-
def update(self, attrs: Dict) -> Optional[Self]:
234+
def update(self, diffsync: "Adapter", attrs: Dict) -> Optional[Self]:
238235
"""Update the attributes of this instance, along with any platform-specific data updates.
239236
240237
Subclasses must call `super().update()` or `self.update_base()`; they may wish to then override the default status information
@@ -250,9 +247,9 @@ def update(self, attrs: Dict) -> Optional[Self]:
250247
Raises:
251248
ObjectNotUpdated: if an error occurred.
252249
"""
253-
return self.update_base(attrs=attrs)
250+
return self.update_base(diffsync=diffsync, attrs=attrs)
254251

255-
def delete_base(self) -> Optional[Self]:
252+
def delete_base(self, diffsync: "Adapter") -> Optional[Self]:
256253
"""Base delete method Delete any platform-specific data corresponding to this instance.
257254
258255
This method is not meant to be subclassed, users should redefine delete() instead.
@@ -263,7 +260,7 @@ def delete_base(self) -> Optional[Self]:
263260
self.set_status(DiffSyncStatus.SUCCESS, "Deleted successfully")
264261
return self
265262

266-
def delete(self) -> Optional[Self]:
263+
def delete(self, diffsync: "Adapter") -> Optional[Self]:
267264
"""Delete any platform-specific data corresponding to this instance.
268265
269266
Subclasses must call `super().delete()` or `self.delete_base()`; they may wish to then override the default status information
@@ -276,7 +273,7 @@ def delete(self) -> Optional[Self]:
276273
Raises:
277274
ObjectNotDeleted: if an error occurred.
278275
"""
279-
return self.delete_base()
276+
return self.delete_base(diffsync=diffsync)
280277

281278
@classmethod
282279
def get_type(cls) -> StrType:

0 commit comments

Comments
 (0)