-
Notifications
You must be signed in to change notification settings - Fork 88
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
fix: Add /delete bidirectional relations in case of owner #206
Conversation
Signed-off-by: dikshathakur3119 <[email protected]>
Signed-off-by: dikshathakur3119 <[email protected]>
CI fails |
Signed-off-by: dikshathakur3119 <[email protected]>
Signed-off-by: dikshathakur3119 <[email protected]>
MATCH {rel_clause} | ||
DELETE rel | ||
""".format(rel_clause=rel_clause)) | ||
if relation_type == UserResourceRel.own: |
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.
could you comment on why we only delete two direction for owning resources?
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.
i c, now wouldn't be an issue for bookmark/follow relationships? to do it generic, let's add bi-direction for all three relationships, and do delete for r1, r2 for all three cases? WDYT?
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.
Yes it would be good to have consistent relations for follow and bookmark as well. I will update it
Signed-off-by: dikshathakur3119 <[email protected]>
8246d12
to
f709816
Compare
Signed-off-by: dikshathakur3119 <[email protected]>
lgtm, thanks @dikshathakur3119 , have you had the chance to deploy this branch to staging for a sanity test? |
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.
lgtm if done a sanity test on Lyft staging
Deploying this branch on staging currently. Will merge after sanity tests. |
Signed-off-by: dikshathakur3119 <[email protected]>
0a43002
to
b58669f
Compare
Signed-off-by: dikshathakur3119 <[email protected]>
Signed-off-by: dikshathakur3119 <[email protected]>
Signed-off-by: dikshathakur3119 <[email protected]>
80478c0
to
1c49649
Compare
any other issues? |
No I did not see any other issue today. Should I merge it or wait till Monday? |
@@ -958,11 +959,14 @@ def _get_user_resource_relationship_clause(relation_type: UserResourceRel, id: s | |||
user_matcher += ' {key: $user_key}' | |||
|
|||
if relation_type == UserResourceRel.follow: | |||
relation = f'(usr{user_matcher})-[rel:FOLLOW]->(resource{resource_matcher})' | |||
relation = f'(resource{resource_matcher})-[r1:FOLLOWED_BY]->(usr{user_matcher})-[r2:FOLLOW]->' \ |
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.
I think those lines should include optional as in the case of deletion. If not then, the existing owners/bookmarks, will not be able to retrieve their existing ones, if they have just one relation and thus it is a breaking change.
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.
yeah, we should make it optional and delete if so. cc @dikshathakur3119 wdyt?
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.
Thanks @PaschalisDim for mentioning, this function is used to create query for add, delete and read, I will fix this function to return appropriate match for each of these cases.
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.
Thanks for taking this over.
@dikshathakur3119
Creation and deletion I guess should be fine. However, when returning what exists, we need to take care to return the ones that were created prior to this MR, so that is the only thing to get altered to include all cases.
Thanks
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.
No actually, that was reason I made this change at first place. If we do delete with existing query, that is A -Relation1->B-Realtion2->A
, it only deletes if there is exact match for bidirectional relation, else it will not make any delete to single relations. And when you use single directional queries to read a relation it will show your deleted tables as well.
Similarly, in case of add, if we add with query A -Relation1->B-Realtion2->A
, it will create duplicate relation if there was existing only one way relation. And this will ultimately cause a loop and you will never be able to delete any owner/bookmark which was added from Frontend UI before this MR .
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.
@PaschalisDim let me know if it makes sense
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.
Hi @dikshathakur3119
Apologies, I was not clear enough here.
So, before this MR let's assume that there is a user who owns and follows a table (table A).
So he will have one relation (usr{user_matcher})<-[rel:OWNER]-(resource{resource_matcher}) and one relation
(usr{user_matcher})-[rel:FOLLOW]->(resource{resource_matcher}).
Then you make this MR.
After we merge this MR and it goes to production,
when the user will try the tables that he owns, the amundsenmeta library will search for (resource{resource_matcher})-[r1:OWNER]->(usr{user_matcher})-[r2:OWNER_OF]->'
f'(resource{resource_matcher})
these type of matches in order to see whether the user owns any table.
Since before this MR the user just had one-directional, the tableA will not show up in the list of the owned tables.
If he adds himself as an owner to another table, tableB, then he will have applied right the bi-directional and he will just see tableB in the list of owned tables.
To the point, for the existing one-way relations this change is a breaking change.
The add functionality should be fine. The get functionality is in my thoughts not right, since it will get just owners that have assigned themselves as owners just only AFTER this MR was deployed while I am not sure about the delete one which needs to be tested after the GET functionality is fixed.
@dikshathakur3119
@dikshathakur3119 |
self.assertEqual(expected, actual) | ||
|
||
actual = neo4j_proxy._get_user_resource_relationship_clause(UserResourceRel.own, | ||
id='foo', | ||
user_key='bar', | ||
resource_type=ResourceType.Table) | ||
expected = '(usr:User {key: $user_key})<-[rel:OWNER]-(resource:Table {key: $resource_key})' | ||
expected = '(resource:Table {key: $resource_key})-[r1:OWNER]->(usr:User {key: $user_key})-[r2:OWNER_OF]->' \ |
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.
@verdan
We need something similar (and precise as well) for atlas as well, what do you think?
Signed-off-by: dikshathakur3119 [email protected]
Summary of Changes
Added Bidirectional relation to add/delete in case of user and owner relationship
When we add or delete an
OWNER
relation from UI, it only deletes one way relation whereas when we do it from extractor, it add bidirectional relations, which is causing some inconsistency in neo4j graph, and creating duplicateOWNER_OF
relations. To make this consistent, bidirectional owner relations will be created by UI API as well.Tests
No new tests added
Documentation
What documentation did you add or modify and why? Add any relevant links then remove this line
CheckList
Make sure you have checked all steps below to ensure a timely review.
make test