-
Notifications
You must be signed in to change notification settings - Fork 519
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
Type casting bugfix #496
base: master
Are you sure you want to change the base?
Type casting bugfix #496
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.
Approving the logic; suggesting change for readability.
@@ -257,7 +257,7 @@ public virtual class fflib_SObjects | |||
{ | |||
for (SObjectField field : fields) | |||
{ | |||
if (String.isNotBlank((String) record.get(field))) continue; | |||
if (String.isNotBlank(String.valueOf(record.get(field)))) continue; |
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.
@ImJohnMDaniel You're a stickler on using explicit blocks for if statements. I think that would be a good measure here too, especially since I had to look at it several time to see why this method wasn't doing the opposite of its name. 😇
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 @stohn777,
First of all, thank you for taking the time to review the PR.
Second, I tend to agree with your comment related to the explicit blocks for if statements but since it's my first time contributing to this codebase, I wasn't sure what are the style conventions so I did not modify that at all.
I also like to enforce these kinds of things, especially the ones that improve the readability and consistency of the codebase and I would have to say that there are many things like this that could be improved in the entire library. If you all agree that this would be something wanted/needed, I would be happy to come up with other PRs to address them. But, since I'm a newbie, I don't want to overstep. I'll follow your lead! Thank you!
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.
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @cnwork)
sfdx-source/apex-common/main/classes/fflib_SObjects.cls
line 185 at r1 (raw file):
for (SObject record : getRecords()) { result.add(String.valueOf(record.get(field)));
I don't know if I agree that this method should return successfully if the SObjectField is for a non-String field. The coercion from a non-String to a String is an ambiguous behavior (DateTime comes to mind .. since the String version is local time to the running user's time zone).
The other changes below where it's testing the 'blankness' (which includes null) is less troublesome.
I would like this change reverted.
Hi @daveespo ,
I propose we keep the current implementation using String.valueOf(record.get(field)) for the following reasons:
To address your valid concern about potential ambiguity, especially for DateTime fields, I suggest we:
P.S. I am not sure why (I guess permissions) but I cannot reply to your comment (made in Reviewable) the same way I was able to reply to @stohn777. |
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 @cnwork,
We discussed this thread internally and are going to reject this change for the same reason I stated in my prior comment. While I appreciate the convenience you're looking for with using this method for any field, its behavior is unpredictable and doesn't belong in the core library. It was not the intent of the author of this method to coerce non-Strings into Strings. Its intent was to get the unique set of String values from the records in the Domain.
We expect a ClassCastException if you attempt to call this method and pass a SObjectField that is not a Text type.
We'd appreciate if you could revert this one change and the rest of the changes are good to be approved.
Thanks!
Reviewable status: 0 of 2 files reviewed, 2 unresolved discussions (waiting on @cnwork and @ImJohnMDaniel)
Hi @daveespo , Thanks for your feedback and nice explanation. I can now understand the reasoning. The Thanks again for all your comments! |
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.
Reviewable status: 0 of 2 files reviewed, 3 unresolved discussions (waiting on @cnwork and @ImJohnMDaniel)
sfdx-source/apex-common/test/classes/fflib_SObjectsTest.cls
line 188 at r2 (raw file):
@IsTest static void itShouldReturnStringFieldValuesForNonStringFields()
@cnwork - sorry, didn't realize this test method was coupled to the change to getStringFieldValues
Rather than revert the entire test method, let's just rename it and have it confirm that a ClassCastException is thrown .. something like
static void getStringFieldValuesShouldThrowClassCastExceptionForNonStringFields{
....
try{
domain.getStringFieldValues(Schema.Account.NumberOfEmployees);
Assert.fail('Expected ClassCastException because NumberOfEmployees is not a Text field');
}catch(ClassCastException expected){
//Expected ClassCastException
}
}
Fixes #495
Replace the manual type casting of field values into String with
String.valueOf()
.This change is