itwinjs-core icon indicating copy to clipboard operation
itwinjs-core copied to clipboard

Entity.forEach throws Error: Cannot get metadata

Open simihartstein opened this issue 7 months ago • 6 comments

Describe the bug When calling entity.forEachProperty, I am getting an error: 'Cannot get metadata for PipeworkPhysical:PipingPhysicalTypeUsesPortTypes'.

This is a regression from iTwinJS 4

To Reproduce Steps to reproduce the behavior:

  1. Open a briefcase,
  2. query for the relationship entity = iModel.relationships.getInstance("PipeworkPhysical:PipingPhysicalTypeUsesPortTypes", "0x2000000022b")
  3. call entity.forEachProperty((propName, propMeta) => {});

This will cause the error.

Expected behavior Should not error.

Desktop (please complete the applicable information):

  • OS: Windows
  • Browser: Electron
  • iTwin.js Version: 5.0.0-dev.118

Additional context Error is coming from Entity.ts#L233

Please consider this a high priority.

@khanaffan, will you please help with this?

simihartstein avatar Jun 15 '25 00:06 simihartstein

Most likely unrelated, but there were changes to TypeScript config in 5.0, which affected classes derived from Entity class.

So if you're using tsconfig from @itwin/build-tools and have classes derived from Entity class, see changelog.

GytisCepk avatar Jun 16 '25 10:06 GytisCepk

Thanks @GytisCepk. The entity object comes directly from core using iModel.relationships.getInstance, so if that is the issue, it would need to be fixed in this repo.

simihartstein avatar Jun 16 '25 13:06 simihartstein

@simihartstein

Is the Cannot get metadata for PipeworkPhysical:PipingPhysicalTypeUsesPortTypes error coming from forEachProperty() or the new forEach()? It seems forEachProperty() is deprecated in 5.0 and recommends forEach() as a replacement. When calling forEachProperty() in 4.11 and forEachProperty() in 5.0 I receive no error. I was able to reproduce the Cannot get metadata error when there is no metadata defined when I call the new forEach() in 5.0.

Can you verify if the error you are seeing is coming from forEachProperty() or forEach() in 5.0? Your link points to forEach() in Entity, not forEachProperty(). If you are using forEach() maybe we can try using the deprecated forEachProperty() in 5.0 in the meanwhile. I will investigate if the error is intended when calling forEach()

MichaelSwigerAtBentley avatar Jun 20 '25 16:06 MichaelSwigerAtBentley

@MichaelSwigerAtBentley

Hi Michael. Sorry for the delay and confusion. Despite the Github issue title (that I corrected), I am using the new Entity.forEach in 5.0.

I am travelling and won't have time until Friday to test thoroughly, but I can at least confirm I don't get an error using the deprecated forEachProperty

simihartstein avatar Jun 25 '25 14:06 simihartstein

@MichaelSwigerAtBentley

Hi Michael. Sorry for the delay and confusion. Despite the Github issue title (that I corrected), I am using the new Entity.forEach in 5.0.

I am travelling and won't have time until Friday to test thoroughly, but I can at least confirm I don't get an error using the deprecated forEachProperty

No worries. I have followed up with @rschili and we believe we have located the issue with forEach(). I am working on a fix right now.

MichaelSwigerAtBentley avatar Jun 25 '25 14:06 MichaelSwigerAtBentley

PR: https://github.com/iTwin/itwinjs-core/pull/8277

MichaelSwigerAtBentley avatar Jun 25 '25 20:06 MichaelSwigerAtBentley

I can still reproduce this as of 5.0.4. I can send you a briefcase with the issue if that would help

simihartstein avatar Aug 18 '25 21:08 simihartstein

I can still reproduce this as of 5.0.4. I can send you a briefcase with the issue if that would help

This fix is not in 5.0.4. I just ckecked. I think you need 5.1. We should probably backport this @MichaelSwigerAtBentley @aruniverse

rschili avatar Aug 19 '25 05:08 rschili

Ah. I thought this had been backported. I updated to 5.1 and can confirm it's fixed!

simihartstein avatar Aug 19 '25 09:08 simihartstein