Skip to content
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

CV2-6041: Verify the relationship target before establishing a new one. #2201

Merged

Conversation

melsawy
Copy link
Contributor

@melsawy melsawy commented Feb 4, 2025

Description

Verify the relationship target before establishing a new one to prevent triggering errors due to database unique validation.

References: CV2-6041

How has this been tested?

Re-run automated tests.

Checklist

  • I have performed a self-review of my own code
  • I have added unit and feature tests, if the PR implements a new feature or otherwise would benefit from additional testing
  • I have added regression tests, if the PR fixes a bug
  • I have added logging, exception reporting, and custom tracing with any additional information required for debugging
  • I considered secure coding practices when writing this code. Any security concerns are noted above.
  • I have commented my code in hard-to-understand areas, if any
  • I have made needed changes to the README
  • My changes generate no new warnings
  • If I added a third party module, I included a rationale for doing so and followed our current guidelines

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@melsawy maybe this is a dumb question: but why not have this logic after the if r.nil? in line 164? Why do we want to check for this in line 161 and then again in 164, but then do something else?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@vasconsaurus the first check against source_id & target_id and also I need to check another case for target_id only to avoid DB validation (unique index for target_id)
I did this before L164 as I need to skip any operation in case there is a relation with same target_id

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the explanation @melsawy!

@melsawy melsawy requested a review from caiosba February 4, 2025 20:56
Comment on lines 160 to 161
r = Relationship.where(target_id: target_id).where.not(source_id: source_id).last
r = Relationship.where(source_id: source_id, target_id: target_id).where('relationship_type = ?', relationship_type.to_yaml).last unless r.nil?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry @melsawy , it's still not clear to me what's the idea here (and I think that we need a comment in this code to explain it, like we had in the other parts of this method).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done and added more comments

@melsawy melsawy requested a review from caiosba February 5, 2025 16:47
Copy link

codeclimate bot commented Feb 5, 2025

Code Climate has analyzed commit 0f1a5a2 and detected 0 issues on this pull request.

The test coverage on the diff in this pull request is 100.0% (100% is the threshold).

This pull request will bring the total coverage in the repository to 100.0% (0.0% change).

View more on Code Climate.

@melsawy melsawy merged commit 7038516 into develop Feb 5, 2025
15 of 16 checks passed
melsawy added a commit that referenced this pull request Feb 7, 2025
…e. (#2201)

* CV2-6041: check relationship target before creating new one

* CV2-6041: apply PR comments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants