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

Fix issue where copy/paste + delete of original association causes association ends to be removed #411

Merged
merged 6 commits into from Aug 25, 2020

Conversation

amolenaar
Copy link
Member

@amolenaar amolenaar commented Aug 19, 2020

PR Type

What kind of change does this PR introduce?

  • Bugfix
  • Feature
  • Code style update (formatting, local variables)
  • Refactoring (no functional changes, no api changes)
  • Documentation content changes

What is the current behavior?

Create a class, connect both ends of an association to it. Copy + paste the association and remove the original.

See tests/test_multiple_associations.py for a failing scenario.

What is the new behavior?

I hope it will work as expected: association ends remain in tact as well as the navigability.

Does this PR introduce a breaking change?

  • Yes
  • No

Notes

This is also applicable for Connectors!

Scenario's I can think of:

  • Class and association are pasted in a new diagram
  • Class and association are pasted in a new diagram and original association is deleted
  • Class and association are pasted in a new diagram and new association is deleted
  • Association is pasted in a new diagram and reconnected to the class (same subject as original)
  • Association is pasted and directly deleted
  • Class and association are pasted in a new diagram and one end is connected to a different class

What's the behavior we're looking for?

  • If an association has >1 presentations, it can only connect to those same types ()
  • If an association has ==1 presentations, it can reconnect to another type, association is updated

@amolenaar amolenaar marked this pull request as draft August 19, 2020 21:24
@amolenaar amolenaar force-pushed the fix-issue-with-copied-associations branch from d35af69 to c185786 Compare August 19, 2020 21:41
@amolenaar amolenaar requested a review from danyeaw August 24, 2020 21:01
@amolenaar amolenaar marked this pull request as ready for review August 24, 2020 21:02
Copy link
Member

@danyeaw danyeaw left a comment

Choose a reason for hiding this comment

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

These changes look great, nice simplifications as well and moves us a step closer to full pytest. I just had a nitpick about spelling and a question.

gaphor/UML/classes/tests/test_associationconnect.py Outdated Show resolved Hide resolved
assert aa.subject.memberEnd[0].type is c.subject
assert aa.subject.memberEnd[1].type is c.subject
assert aa.subject.memberEnd[0] is aa.head_end.subject
assert aa.subject.memberEnd[1] is aa.tail_end.subject
Copy link
Member

Choose a reason for hiding this comment

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

I'm sure this is my misunderstanding, if the original a is deleted, I would think that the copy of a called aa is also deleted. Why would these assert statements pass?

Copy link
Member Author

@amolenaar amolenaar Aug 25, 2020

Choose a reason for hiding this comment

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

a is an AssociationItem, aa is also an AssociationItem. Both point to the same association (the subject). If I remove one, the model should not change, since there's still a presentation of the Association model element in a diagram.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for the explanation 👍

@sourcery-ai
Copy link
Contributor

sourcery-ai bot commented Aug 25, 2020

Sourcery Code Quality Report (beta)

✅  Merging this PR will increase code quality in the affected files by 0.03 out of 10.

Quality metrics Before After Change
Complexity 1.40 1.52 0.12 🔴
Method Length 54.86 52.56 -2.30 🔵
Quality 8.63 8.66 0.03 🔵
Other metrics Before After Change
Lines 1517 1480 -37
Changed files Quality Before Quality After Quality Change
gaphor/UML/classes/association.py 8.71 8.76 0.05 🔵
gaphor/UML/classes/classconnect.py 8.47 8.48 0.01 🔵
gaphor/UML/classes/classespropertypages.py 8.88 8.85 -0.03 🔴
gaphor/UML/classes/tests/test_association.py 8.45 8.63 0.18 🔵
gaphor/UML/classes/tests/test_classconnect.py 7.97 7.94 -0.03 🔴

Here are some functions in these files that still need a tune-up:

File Function Complexity Length Overall Recommendation
gaphor/UML/classes/association.py AssociationEnd.post_update 17 351.75 3.65 Split out functionality
gaphor/UML/classes/association.py AssociationItem.post_update 17 183.87 4.73 Split out functionality
gaphor/UML/classes/classespropertypages.py AssociationPropertyPage.construct 9 196.75 5.34 Split out functionality
gaphor/UML/classes/classespropertypages.py OperationsPage.construct 6 168.76 5.96 Split out functionality
gaphor/UML/classes/classespropertypages.py AttributesPage.construct 6 154.80 6.16 Split out functionality

Please see our documentation here for details on how these metrics are calculated.

We are actively working on this report - lots more documentation and extra metrics to come!

Let us know what you think of it by mentioning @sourcery-ai in a comment.

@amolenaar amolenaar merged commit c1671d6 into master Aug 25, 2020
@amolenaar amolenaar deleted the fix-issue-with-copied-associations branch August 25, 2020 19:03
@danyeaw danyeaw added the bug An issue in the application label Aug 28, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue in the application
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants