-
Notifications
You must be signed in to change notification settings - Fork 60
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Skip replicating empty relations when deleting role #1429
Conversation
@astrozzc can you describe what is reason that relations are empty ? is because that role doesn't have any assignments ? |
0d486b8
to
2421e0b
Compare
Yea, the created role has empty access, so there is no relations created for it, and no bindingmapping. When deleting it, there is no relationships to delete too, which explains why the delete/create has almost the same number. |
Didn't take too close a look but if possible please add logging any time we are not replicating (info level is probably appropriate, I think that's what we do in some other places. Possibly warning if it's unexpected.) |
Updated with logging. Using info to distinguish with the unexpected skipping replication events |
@@ -274,17 +283,31 @@ def replicate_new_or_updated_role(self, role): | |||
return | |||
self.role = role | |||
self._generate_relations_and_mappings_for_role() | |||
# No need to replicate if creating role with empty access, which won't have any relationships | |||
if not role.access.all() and self.event_type == ReplicationEventType.CREATE_CUSTOM_ROLE: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Overall idea looks to me.
My concern is whether we should put this logic in to dual write handler or in view/perform_ methods, build _expected_empty_relation_reason
here pass it in dual write handler and into replicator.
Replicator will output log info message about the reason.
Reason is that it will not complicate dual write handler methods.
example:
# check emptiness
if not role.access.all():
expected_empty_relation_reason = <build reason>
dual_write_handler = RelationApiDualWriteHandler(instance, ReplicationEventType.DELETE_CUSTOM_ROLE)
if not role.access.all():
dual_write_handler.set_expected_empty_relation_reason_to_replicator(expected_empty_relation_reason)
or
dual_write_handler.replicator.set_expected_empty_relation_reason(expected_empty_relation_reason)
else:
dual_write_handler.prepare_for_update()
self.delete_policies_if_no_role_attached(instance)
instance.delete()
dual_write_handler.replicate_deleted_role() # this will output only log message as replicator will react on set expected_empty_relation_reason
role_obj_change_notification_handler(instance, "deleted", self.request.user)
it is just suggestion please let me know what do you think about it.
4334755
to
4b16ecd
Compare
/retest |
…ross account request
Link(s) to Jira
Description of Intent of Change(s)
The what, why and how.
Local Testing
How can the feature be exercised?
How can the bug be exploited and fix confirmed?
Is any special local setup required?
Checklist
Secure Coding Practices Checklist Link
Secure Coding Practices Checklist