Skip to content

fix(salesforce): default exported field label to apiName - #514

Merged
jbonofre merged 1 commit into
apache:mainfrom
RyutoYoda:fix/salesforce-field-label-default
Oct 6, 2026
Merged

jbonofre merged 1 commit into
apache:mainfrom
RyutoYoda:fix/salesforce-field-label-default

Conversation

@RyutoYoda

@RyutoYoda RyutoYoda commented Oct 5, 2026 •

Copy link
Copy Markdown
Contributor

Summary

#512 defaulted a metric's label to its apiName, "matching DatasetMappingHandler /
SemanticModelMappingHandler". FieldMappingHandler is the one handler still without
it, so an exported semanticDimension, semanticMeasurement or
semanticCalculatedDimension carries a label only when the Ossie field sets one or
custom_extensions restored one. A field's label is optional in the schema and has no
minLength, so a hand-authored model may omit it or set it to "". Salesforce requires
MasterLabel and rejects every one of those the same way on create:

HTTP 500
common.udd.object.RequiredFieldException: [MasterLabel]   (message localized by the org)

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 extensions
and already holds the displayCategory default, so a restored exact Salesforce label
still wins and both export paths are covered by the one call site.

Verification

  • mvn -B clean verify in converters/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).
  • Each arm of the guard is covered: reverting the default, weakening it back to
    !containsKey(LABEL), dropping the null arm, dropping the blank arm, and moving
    applyFieldDefaults ahead of the custom-extension restore each turn a test red.
  • End-to-end against a live Tableau Next org, one payload with only a measurement's
    label varied: "Profit" → 201; key absent, "", " " and null → the 500
    above. On this branch the same model exports with labels, returns 201, and
    /validate reports isValid: 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

  • Converter logic updated
  • Tests live under the converter's test directory

Tests

  • All existing tests pass: 289 passed, 0 skipped locally; green on the CI profile
  • New functionality is covered by tests, and they fail without the fix

Compliance

  • ASF license headers present (no new files added)
  • No third-party dependencies added

Comment on lines +545 to +547
* <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.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Suggested change
* <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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +553 to +555
if (!sfField.containsKey(LABEL) && sfField.containsKey(API_NAME)) {
sfField.put(LABEL, getString(sfField, API_NAME));
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Two things on the guard:

  • containsKey(LABEL) is true for an empty, blank or null label (label: "" in the model, or "label": null in custom_extensions), so those are exported as-is and never defaulted. I would expect Salesforce to treat them like a missing MasterLabel. Can you confirm?
  • containsKey(API_NAME) is always true here, since both mapFieldProperties and createSemanticCalculatedDimension put API_NAME unconditionally. Checking the value is what actually protects against a null name.
Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Comment on lines +334 to +335
assertEquals("Product ID", productId.get("label"),
"an explicit Ossie label should still win over the apiName default");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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)".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Added testFieldLabelFromCustomExtensionsWinsOverApiNameDefault. Moving applyFieldDefaults ahead of restoreSalesforceCustomExtension makes it fail with expected: <Product Name (Custom Label)> but was: <product_name>.

Comment on lines +306 to +307
assertFalse(yamlWithoutLabels.contains("Product Name"), "fixture text substitution did not match");
assertFalse(yamlWithoutLabels.contains("Stock Level"), "fixture text substitution did not match");

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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:

Suggested change
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");

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Applied.

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.
@RyutoYoda
RyutoYoda force-pushed the fix/salesforce-field-label-default branch from 18231a3 to ea1caea Compare October 6, 2026 01:31
@RyutoYoda
RyutoYoda requested a review from jbonofre October 6, 2026 01:45

@jbonofre jbonofre left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

@jbonofre
jbonofre merged commit 7f17a07 into apache:main Oct 6, 2026
6 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants