Skip to content

Commit b1140f6

Browse files
committed
Refactor the whole thing to do a save override
1 parent 7661810 commit b1140f6

File tree

1 file changed

+4
-8
lines changed

1 file changed

+4
-8
lines changed

ansible_base/rbac/models.py

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -389,18 +389,14 @@ class Meta:
389389
app_label = 'dab_rbac'
390390
abstract = True
391391

392-
def __init__(self, *args, **kwargs):
393-
super().__init__(*args, **kwargs)
394-
395-
# Fields from object_role are cached onto assignment objects, only when creating new assignments
396-
# we must be very careful to avoid referencing deferred attributes to avoid RecursionError
397-
def_fields = self.get_deferred_fields()
398-
if not ({'id', 'object_id', 'object_role_id'} & def_fields):
399-
if (not self.id) and self.object_role_id and (not self.object_id):
392+
def save(self, *args, **kwargs):
393+
if not self.id: # usually only new objects can be saved, but super needs to do error handling
394+
if self.object_role_id and (not self.object_id):
400395
# Cache fields from the associated object_role
401396
self.object_id = self.object_role.object_id
402397
self.content_type_id = self.object_role.content_type_id
403398
self.role_definition_id = self.object_role.role_definition_id
399+
return super().save(*args, **kwargs)
404400

405401

406402
class RoleUserAssignment(AssignmentBase):

0 commit comments

Comments
 (0)