-
Notifications
You must be signed in to change notification settings - Fork 518
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
bugfix for Issue 221 #449
base: master
Are you sure you want to change the base?
bugfix for Issue 221 #449
Conversation
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.
Please add a test covering this scenario for regression-prevention sake.
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.
@jprichter
The new test DOES NOT fail with the preceding version of fflib_SObjectUnitOfWork.
Correct. One way to get it to fail before the change and pass after is to commit to the database instead of using the MockDML. Figured that wouldn't fly. |
@jprichter, I am a bit confused then by your comment. I would expect that the test case, applied to the current version of the codebase (not this PR branch) would fail. Is that a correct assumption or am I missing something? |
@ImJohnMDaniel , the scenario is relating an existing record to a new record. One way to test this is to commit to the database so we have an Id from the newly created record. If you run the test like this, we'll see that the unit test fails on the version that's in master and passes in the version that's in the PR. The mocking framework does not create fake Ids after mocking the insert. I'm open to guidance on how to better test this scenario using mocking. |
Does this test add value then? My initial guess is that it does not since the errant code passes the test. Generally we try to avoid actual DML in tests, but some times, it's needed to properly execute the code being tested. However some gray exists between that and a test of Salesforce functionality exclusively. If we can craft a test that properly recreates the problem, using actual DML to add value through testing this feature, without simply testing Salesforce functionality. Otherwise then adding a test that does NOT add value is pointless. |
public void dmlInsert(List<SObject> objList) | ||
{ | ||
for (SObject obj : objList) { | ||
obj.Id = fflib_IDGenerator.generate(obj.getSObjectType()); |
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.
@ClayChipps and @jprichter -- Please add a null check on obj
before trying to generate the mock Id.
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.
done
@@ -848,6 +905,43 @@ private with sharing class fflib_SObjectUnitOfWorkTest | |||
} | |||
} | |||
|
|||
private class MockDMLWithInsertIds implements fflib_SObjectUnitOfWork.IDML |
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.
@ClayChipps and @jprichter -- Any reason why you did not just simply modify the existing MockDML
??
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.
Updated to use the existing MockDML.
This bug only presents itself when the Unit of Work has SObjects registered in a certain order. Here is a sample scenario where the current implementation fails: Lets assume we have two SObjects that we are about to register to a Unit of Work.
We have registered the Unit of Work such that
We then attempt to perform the following operation:
This will fail as when the Unit of Work reaches the insertDmlByType, it will first process all Opportunity relationship resolutions (even though no Opportunity has been registered new), and then process the insert and resolution of all Account relationships. Then when the Unit of Work reaches the updateDmlByType, the relationship resolution is not invoked again, and thus the relationship that was registered has never been resolved after the Account insert. The initial fix was to add a call to This causes a separate issue that was exposed by the InvoicingServiceTest. The The solution here was to modify the Relationship resolver to remove relationships from the registered relationships list as they are successfully resolved, so that previously resolved relationships are not resolved a second time. |
@ClayChipps and @jprichter -- After more discussion on this PR, we would like to conduct a test of your changes in a real world series of codebases to assess any functional or performance impacts. I will reach out to you two directly to discuss this in detail. Thanks again for the help! |
fix for #221 from @dsurfleet
This change is