Skip to content

create or modify external entity wipes omitted RemoteName/EntityTypeName (Studio Pro NRE in ODataRemoteEntitySource.RemoteId) #594

@ako

Description

@ako

Summary

create or modify external entity overwrites RemoteEntityName (the BSON RemoteName field on Rest\$ODataRemoteEntitySource) with the empty string when the RemoteName property is omitted from the statement. The resulting Rest\$ODataRemoteEntitySource BSON has \"RemoteName\": \"\", which Studio Pro's Integration Pane visualiser cannot render — ODataRemoteEntitySource.get_RemoteId() throws ArgumentNullException(\"EntityTypeName\") (Studio Pro internally aliases the BSON RemoteName field to the C# property EntityTypeName).

Studio Pro should also null-check here (separate upstream robustness gap), but the root cause on our side is that omitted properties in or modify are being treated as "reset to empty" rather than "preserve existing value".

Reproduction

-- First create with RemoteName set
create external entity OdTest.RemoteAccount
from odata client OdTest.SalesforceAPI
(
  EntitySet: 'Accounts',
  RemoteName: 'Account',
  Countable: Yes
)
( AccountId: string(200) );

-- Then `or modify` it WITHOUT RemoteName
create or modify external entity OdTest.RemoteAccount
from odata client OdTest.SalesforceAPI
(
  EntitySet: 'Accounts',
  Countable: Yes,
  AllowCreateChangeLocally: Yes
)
( AccountId: string(200) );

Resulting BSON (from a real project, observed after running mdl-examples/doctype-tests/10-odata-examples.mdl):

{
  \"\$Type\": \"Rest\$ODataRemoteEntitySource\",
  \"EntitySet\": \"Accounts\",
  \"RemoteName\": \"\",
  \"SourceDocument\": \"OdTest.SalesforceAPI\",
  ...
}

Then opening the project in Studio Pro and switching to the Integration view triggers:

System.ArgumentNullException: Value cannot be null. (Parameter 'EntityTypeName')
   at Mendix.Modeler.Integration.ODataRemoteEntitySource.get_RemoteId() in
      Mendix.Modeler.Integration/ODataServices/Consume/ODataRemoteEntitySource.cs:line 51
   at Mendix.Modeler.Integration.View.ODataServices.Consume.ODataApiVisualizer ...
   at Mendix.Modeler.IntegrationOverview.View.LandscapeSearch.GetUsedInApp()
   at Mendix.Modeler.IntegrationOverview.View.Web.IntegrationPaneWebApiHandler.HandleUsedInAppRequest()
   ...

Root cause

mdl/executor/cmd_odata.go:818 (the or modify branch of the create-external-entity handler):

if existingEntity != nil {
    existingEntity.Source = \"Rest\$ODataRemoteEntitySource\"
    existingEntity.RemoteServiceName = serviceRef
    existingEntity.RemoteEntitySet = s.EntitySet
    existingEntity.RemoteEntityName = s.RemoteName  // <-- overwrites with \"\" when omitted
    existingEntity.Countable = s.Countable
    ...
}

When the MDL parser sees no RemoteName property, s.RemoteName is \"\". The handler unconditionally assigns it, wiping the prior non-empty value.

The non-modify branch (line 849 — initial create) has the same shape but is correct: the BSON for a fresh create is well-formed even with empty RemoteName (Studio Pro probably defaults it). The bug is specifically in the modify path overwriting a pre-existing valid value.

Proposed fix

Guard the assignment so omitted properties preserve existing values:

if s.RemoteName != \"\" {
    existingEntity.RemoteEntityName = s.RemoteName
}

The same review should be applied to other fields in this block — EntitySet, Countable, Creatable, Deletable, Updatable, CreateChangeLocally, Documentation. The current handler already guards Documentation and Attributes (lines 824-829) but treats the boolean/scalar fields as required-on-every-modify.

Two design options:

  1. Preserve when omitted — matches SQL UPDATE ... SET column = X semantics. Requires the parser to distinguish "omitted" from "explicitly empty" — currently the AST collapses both to \"\". Boolean fields would need a *bool AST type (or a separate "was set" bitmap).
  2. Require explicit RemoteName on or modify — simpler but breaks the upsert pattern.

Option 1 is the right long-term fix; option 2 is a stopgap that gives a clear error rather than silent corruption.

Workaround (example file)

mdl-examples/doctype-tests/10-odata-examples.mdl Level 8.6c is being patched in PR #592 to explicitly set RemoteName: 'Account', sidestepping the bug for the example file. The underlying executor bug remains.

Related

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions