Repository navigation
fix(salesforce): default exported field label to apiName - #514
Conversation
| * <p>Ossie fields have no label, so an exported dimension or measurement carries one only | ||
| * when custom_extensions restored it. Salesforce requires a label, so it falls back to the | ||
| * apiName, matching DatasetMappingHandler/MetricMappingHandler. |
There was a problem hiding this comment.
I think this isn't accurate for fields: label is an optional property of an Ossie field (core-spec/ossie-schema.json), mapFieldProperties copies it to the Salesforce field, and the new test below relies on that ("an explicit Ossie label should still win"). It reads like it was carried over from MetricMappingHandler, where it is true.
| * <p>Ossie fields have no label, so an exported dimension or measurement carries one only | |
| * when custom_extensions restored it. Salesforce requires a label, so it falls back to the | |
| * apiName, matching DatasetMappingHandler/MetricMappingHandler. | |
| * <p>An Ossie field's label is optional, so an exported dimension or measurement carries | |
| * one only when the field sets it or custom_extensions restored it. Salesforce requires a | |
| * label, so it falls back to the apiName, matching | |
| * DatasetMappingHandler/MetricMappingHandler. |
There was a problem hiding this comment.
Applied. I also fixed the line above it: with the new guard, "Only sets defaults if the property is not already present" no longer holds.
| if (!sfField.containsKey(LABEL) && sfField.containsKey(API_NAME)) { | ||
| sfField.put(LABEL, getString(sfField, API_NAME)); | ||
| } |
There was a problem hiding this comment.
Two things on the guard:
containsKey(LABEL)is true for an empty, blank or null label (label: ""in the model, or"label": nullincustom_extensions), so those are exported as-is and never defaulted. I would expect Salesforce to treat them like a missingMasterLabel. Can you confirm?containsKey(API_NAME)is always true here, since bothmapFieldPropertiesandcreateSemanticCalculatedDimensionputAPI_NAMEunconditionally. Checking the value is what actually protects against a null name.
| if (!sfField.containsKey(LABEL) && sfField.containsKey(API_NAME)) { | |
| sfField.put(LABEL, getString(sfField, API_NAME)); | |
| } | |
| String apiName = getString(sfField, API_NAME); | |
| Object label = sfField.get(LABEL); | |
| if (apiName != null && (label == null || label.toString().isBlank())) { | |
| sfField.put(LABEL, apiName); | |
| } |
I know this mirrors the existing blocks in DatasetMappingHandler and MetricMappingHandler, those have the same gap and can be fixed separately.
There was a problem hiding this comment.
Confirmed. Same payload against a live org, only the label varied: "Profit" -> 201; key absent, "", " " and null -> 500 RequiredFieldException: [MasterLabel]. Blank and null are treated as missing.
Applied your suggestion, and added testBlankOrNullFieldLabelIsDefaultedToApiName for label: "" and for a null label restored from custom_extensions. I kept the javadoc's "matching DatasetMappingHandler/MetricMappingHandler" since the fallback target is the same; happy to take their guards in a follow-up.
| assertEquals("Product ID", productId.get("label"), | ||
| "an explicit Ossie label should still win over the apiName default"); |
There was a problem hiding this comment.
Nit: this pins "Ossie label wins over the default". The other ordering the description relies on, a label restored from custom_extensions winning over the default, isn't covered for fields. If applyFieldDefaults were ever moved about of restoreSalesforceCustomExtension, the default would shadow every restored label and the suite would stay green.
Could you add a case for a field with no Ossie label and a SALESFORCE custom_extensions label, asserting the restored one is exported? The metric test just below does this with "Total Revenue (Custom Label)".
There was a problem hiding this comment.
Added testFieldLabelFromCustomExtensionsWinsOverApiNameDefault. Moving applyFieldDefaults ahead of restoreSalesforceCustomExtension makes it fail with expected: <Product Name (Custom Label)> but was: <product_name>.
| assertFalse(yamlWithoutLabels.contains("Product Name"), "fixture text substitution did not match"); | ||
| assertFalse(yamlWithoutLabels.contains("Stock Level"), "fixture text substitution did not match"); |
There was a problem hiding this comment.
Nit: these check that the text appears nowhere in the fixture, so they would fail with a misleading message if someone later adds e.g. description: Product Name (other fields in the fixture already repeat their label in the description). The scoped form you use ini the second test is safer:
| assertFalse(yamlWithoutLabels.contains("Product Name"), "fixture text substitution did not match"); | |
| assertFalse(yamlWithoutLabels.contains("Stock Level"), "fixture text substitution did not match"); | |
| assertFalse(yamlWithoutLabels.contains("label: Product Name"), "fixture text substitution did not match"); | |
| assertFalse(yamlWithoutLabels.contains("label: Stock Level"), "fixture text substitution did not match"); |
An Ossie field's label is optional and the schema puts no minLength on it, so an exported semanticDimension, semanticMeasurement or semanticCalculatedDimension could carry no label, an empty one, or a null restored from custom_extensions. Salesforce requires MasterLabel on every field and rejects all three the same way on create: RequiredFieldException: [MasterLabel] Fall back to the apiName in applyFieldDefaults, which already runs after custom extensions so a restored exact Salesforce label still wins. This matches DatasetMappingHandler, SemanticModelMappingHandler and the metric fix in apache#512; FieldMappingHandler was the one handler left without it.
18231a3 to
ea1caea
Compare
jbonofre
left a comment
There was a problem hiding this comment.
LGTM! applyFieldDefaults now falls back to the field's apiName when the label is missing, null or blank. It runs after custom-extension restoration and datatype mapping on both the calculated-dimension and regular paths, so labels restored from custom_extensions still take precedence.
The apiName != null guard avoids writing a null label. The new tests assert that each fixture replacement matched, so they won't pass silently if the fixture changes. CI is green.
Summary
#512 defaulted a metric's
labelto itsapiName, "matchingDatasetMappingHandler/SemanticModelMappingHandler".FieldMappingHandleris the one handler still withoutit, so an exported
semanticDimension,semanticMeasurementorsemanticCalculatedDimensioncarries a label only when the Ossie field sets one orcustom_extensionsrestored one. A field'slabelis optional in the schema and has nominLength, so a hand-authored model may omit it or set it to"". Salesforce requiresMasterLabeland rejects every one of those the same way on create:Models imported from an org are unaffected, because their labels survive in
custom_extensions— only hand-written ones hit this.The fallback goes in
applyFieldDefaults, which already runs after custom extensionsand already holds the
displayCategorydefault, so a restored exact Salesforce labelstill wins and both export paths are covered by the one call site.
Verification
mvn -B clean verifyinconverters/salesforce: 289 tests, 0 failures, 0 errors,0 skipped with the Salesforce schema installed per the README; same count green
without it, with only the 15 pre-existing schema-gated skips (the CI profile).
!containsKey(LABEL), dropping the null arm, dropping the blank arm, and movingapplyFieldDefaultsahead of the custom-extension restore each turn a test red.labelvaried:"Profit"→201; key absent,""," "andnull→ the500above. On this branch the same model exports with labels, returns
201, and/validatereportsisValid: true. The test model was deleted afterwards.Related Issues
Follow-on to #512, one level down. No existing issue covers this.
Checklist
Sections this change does not touch (Specification, Ontology, Validation,
Documentation, Examples) are omitted rather than left unchecked.
Converters
Tests
Compliance