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

Validation to disallow multiple create on related entities backed by same database table #2189

Conversation

ayush3797
Copy link
Contributor

@ayush3797 ayush3797 commented Apr 26, 2024

Why make this change?

DAB doesn't support multiple-create on related entities which are backed by same database table. This PR adds a validation to catch that scenario and throw a meaningful exception to the end user. Issue to track support: #2157

What is this change?

  • Adds a validation during order determination logic in MultipleCreateOrderHelper.GetReferencingEntityName() method to catch the scenario.
  • In the method signature for MultipleCreateOrderHelper.GetReferencingEntityName(), a new parameter isMNRelationship is added with default value of false. The reasoning is explained in the section.

Reason for why MultipleCreateOrderHelper.GetReferencingEntityName() is called even for M:N relationships when we know that we are always going to return an empty string?

  1. For M:N relationships, we assume one of the source/target entity as the referencing entity when we do insertion during query execution because any of the entity can be considered as the referencing/referenced entity. However this does not hold true when the source and target entities are backed by same database tables - in which case we cannot consider any of the entity as the referenced/referencing entity.
  2. The not-supported use case - that of not allowing multiple-create via relationships in which source and target entities are backed by same database tables is because DAB cannot determine a valid order of insertion. Since this concerns order determination, it is better to keep the code inside the MultipleCreateOrderHelper.GetReferencingEntityName() method.
  3. Keeping this in MultipleCreateOrderHelper provides unit test coverage even for the other 2 db types i.e. PgSql,MySql.

How was this tested?

  • Added test MultipleCreateOrderHelperUnitTests.TestExceptionForSelfReferencingRelationships() to test the change for the 3 dbs - MySql/MsSql/PgSql.

Sample Request(s)

  1. Config:

image

Request:

image

@ayush3797 ayush3797 self-assigned this Apr 26, 2024
@ayush3797 ayush3797 added the Multiple mutations Fixes/enhancements related to nested mutations. label Apr 26, 2024
@ayush3797 ayush3797 added this to the 0.12rc2 milestone Apr 26, 2024
@ayush3797
Copy link
Contributor Author

/azp run

Copy link
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

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

are tests dependent on #2138

@ayush3797
Copy link
Contributor Author

are tests dependent on #2138

Are not dependent. But will require additional entities in the config and some more changes. Keeping bug-bash in mind, trying to get the logic changes in and test can follow.

@ayush3797
Copy link
Contributor Author

Now I'm onto adding test.

@ayush3797
Copy link
Contributor Author

/azp run

Copy link
Contributor

@Aniruddh25 Aniruddh25 left a comment

Choose a reason for hiding this comment

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

Waiting on safe typecast to DatabaseTable

Copy link
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

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

dont need isMNRelationship as a param to getreferencingEntityName otherwise looks good. As Ani mentioned, casting feedback needs addressing

src/Core/Resolvers/MultipleCreateOrderHelper.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@seantleonard seantleonard left a comment

Choose a reason for hiding this comment

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

need not block on my feedback, only Ani's. Go ahead and make those changes and you should be good from my end. Let me know if you think we really need to keep isMNRelationship param.

@seantleonard seantleonard modified the milestones: 0.12rc2, 1.1rc Apr 30, 2024
ayush3797 and others added 5 commits May 1, 2024 14:47
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: Sean Leonard <sean.leonard@microsoft.com>
…eateOrderHelperUnitTests.cs

Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
…eateOrderHelperUnitTests.cs

Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
Co-authored-by: Aniruddh Munde <anmunde@microsoft.com>
@ayush3797 ayush3797 changed the title Validation to disallow mutations on related entities backed by same database table Validation to disallow multiple mutations on related entities backed by same database table May 1, 2024
@ayush3797 ayush3797 changed the title Validation to disallow multiple mutations on related entities backed by same database table Validation to disallow multiple create on related entities backed by same database table May 1, 2024
@ayush3797 ayush3797 dismissed Aniruddh25’s stale review May 1, 2024 09:49

Addressed review

@ayush3797
Copy link
Contributor Author

/azp run

@ayush3797
Copy link
Contributor Author

/azp run

@ayush3797 ayush3797 enabled auto-merge (squash) May 1, 2024 10:17
@ayush3797
Copy link
Contributor Author

/azp run

@ayush3797
Copy link
Contributor Author

/azp run

@ayush3797 ayush3797 merged commit ec56744 into main May 2, 2024
7 checks passed
@ayush3797 ayush3797 deleted the dev/agarwalayush/prohibitSelfReferencingRelationshipForMutations branch May 2, 2024 06:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Multiple mutations Fixes/enhancements related to nested mutations.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants