Skip to content

PublishedODataService EntityTypePointer never set — Studio Pro NRE in EntitySet.Check #595

@ako

Description

@ako

Summary

serializePublishedODataService (sdk/mpr/writer_odata.go:248) tries to resolve each EntitySet's owning EntityType through an internal map keyed by the wrong field. The lookup always returns empty, so the EntityTypePointer field is never written on ODataPublish\$EntitySet sub-documents. Studio Pro's EntitySet.Check (Mendix.Modeler.Integration.ODataServices.Publish.EntitySet.Check, line 53) then dereferences null and aborts the entire project checker with a NullReferenceException — hiding all other problems in the project, not just the published OData service.

Stack trace

System.AggregateException: One or more errors occurred. (Object reference not set to an instance of an object.)
 ---> System.NullReferenceException: Object reference not set to an instance of an object.
   at Mendix.Modeler.Integration.ODataServices.Publish.EntitySet.Check(IProblems problems)
      in Mendix.Modeler.Integration/ODataServices/Publish/EntitySet.cs:line 53
   at Mendix.Modeler.Storage.TypeWalks.TypeWalk.ForEachObjectDo[TObject](...)
   ...
   at Mendix.Modeler.Core.View.Problems.BackgroundCheckRunner.Check(IProject project, CancellationToken cancellationToken)

Root cause

In sdk/mpr/writer_odata.go:

// Line 235 — map keyed by ExposedName
entityTypeIDMap[et.ExposedName] = etID

// Line 248 — lookup by EntityTypeName (which holds the qualified entity name)
entityTypeID := entityTypeIDMap[es.EntityTypeName]

PublishedEntityType.ExposedName is the OData-facing name (e.g. \"Customers\").
PublishedEntitySet.EntityTypeName is the qualified entity name (e.g. \"OdTest.Customer\", set in astEntityDefToModel at mdl/executor/cmd_odata.go:1544).

These are different values, so the lookup returns \"\". In serializePublishedEntitySet (line 305):

if entityTypeID != \"\" {
    doc[\"EntityTypePointer\"] = idToBsonBinary(entityTypeID)
}

The condition is always false → EntityTypePointer is never written. Studio Pro then can't navigate from EntitySet to its EntityType and NREs.

Reproduction

Run any MDL script that creates a published OData service with at least one publish entity block, then open the project in Studio Pro:

create persistent entity Demo.Customer ( Name: string(200) );

create odata service Demo.CustomerAPI (
  path: '/odata/customers',
  version: '1.0.0',
  ODataVersion: OData4,
  namespace: 'Demo.Customers'
)
authentication basic
{
  publish entity Demo.Customer as 'Customers' ( ReadMode: source )
  expose (*);
};

The resulting ODataPublish\$EntitySet BSON has no EntityTypePointer field. Confirmed by inspecting mprcontents/**/*.mxunit from a real project — every EntitySet sub-document is missing the field.

Proposed fix

One-line change in sdk/mpr/writer_odata.go:235:

-    entityTypeIDMap[et.ExposedName] = etID
+    entityTypeIDMap[et.Entity] = etID

et.Entity is the qualified entity name (\"OdTest.Customer\"), matching how EntityTypeName is set on the corresponding EntitySet.

Add a test in sdk/mpr/writer_odata_test.go that asserts the EntitySet's EntityTypePointer matches the EntityType's \$ID. The existing TestSerializePublishedODataService covers other fields but not this pointer, which is why the bug landed undetected.

Related

  • mxcli#590 — sibling Studio Pro NRE (CallExternalAction.SchemaAction) from the same example file
  • mxcli#594 — sibling Studio Pro NRE (ODataRemoteEntitySource.RemoteId) from the same example file
  • mxcli#592 — example-file workarounds; this issue is the underlying writer bug

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