Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cannot create property '__metadata' on number '5' ( intermittent ) #108

Closed
sreehari-pillai-atom opened this issue Dec 17, 2024 · 10 comments
Closed
Assignees

Comments

@sreehari-pillai-atom
Copy link

sreehari-pillai-atom commented Dec 17, 2024

I have an association from /Materials(key)?$expand=ItsMaterialType/ItsText , where ItsMaterialType ( corresponding entity ) has a LargeString in its property. This call gives 500 , intermittent , the below stack trace. Running the same URL again works perfectly. Something to do with cache ?

{
"stacktrace": [
      "TypeError: Cannot create property '__metadata' on number '5'",
      "at addMetadata (/home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:3650:21)",
      "at /home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:3561:7",
      "at Array.forEach (<anonymous>)",
      "at convertResponseData (/home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:3560:10)",
      "at /home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:3539:13",
      "at Array.forEach (<anonymous>)",
      "at /home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:3530:25",
      "at Array.forEach (<anonymous>)",
      "at convertResponseData (/home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:3529:10)",
      "at convertResponseBody (/home/vcap/app/node_modules/@cap-js-community/odata-v2-adapter/src/index.js:3388:11)"
    ]
}
@oklemenz2 oklemenz2 self-assigned this Dec 17, 2024
@oklemenz2
Copy link
Contributor

oklemenz2 commented Dec 17, 2024

I will check, can you share the relevant parts of your model? What is ItsText?

@oklemenz2
Copy link
Contributor

BTW. Which version of @cap-js-community/odata-v2-adapter do you use? Line 3650 does not match addMetadata function.

Can you try latest version: 1.13.8

@sreehari-pillai-atom
Copy link
Author

sreehari-pillai-atom commented Dec 18, 2024

this is the abstract - meanwhile let be change to 1.13.8 and give it a try. My primary observation is, I had a GET call to another API , with in which I am updating a table. The immediate GET call to an unrelated entity was throwing 404 / 500 randomly - I suspect some sort of a db lock or so for the 404. 500 is due the the metadata caching ?

I commented the DB update and its smooth for now. Somewhere its inconsistent

entity Materials 
{
key ID : Integer; 
  MATERIAL_TYPE_ID : Integer ; 
  ItsMaterialType : Association to one MaterialType on ItsMaterialType.ID = $self.MATERIAL_TYPE_ID; 
}

entity MaterialType 
{
    key ID : Integer ; 
    DESCRIPTION : LargeString;
    TEXT_ID : Integer; 
     ItsText : Association to one MaterialTypeText on ItsText.ID = $self.TEXT_ID ; 
}

entity MaterialTypeText 
{
  key ID : Integer ; 
  TEXT : LargeText ; 
}

@oklemenz2
Copy link
Contributor

Thanks for the model. I looks very common, but I will check.

You can explain where the 5 is coming from in Cannot create property '__metadata' on number '5'"?
Do you have the payload of that response, that is coming to the OData V2 adapter?

Do you have a new callstack trace when the exception happens, so that I at least can match the line, where the error occurs?

I don't think it's related to any caches, but it seems to be a race condition... Are use missing an await somewhere in your handlers GET api call? That could explain this behavior?...

@oklemenz2
Copy link
Contributor

I provided a fix, that prevents the crashing of response conversion: 890b8ba

Will be part of next release, beginning of next year.

Still I guess the OData V4 response is malformed in some cases, so you should check, why you have a number 5 in our response payload for and expand element, which normally should be an object or array of objects...

@sreehari-pillai-atom
Copy link
Author

Awesome. Let me test this commit

Copy link

github-actions bot commented Jan 3, 2025

This issue is stale because it has been open for 14 days with no activity.

@github-actions github-actions bot added the stale label Jan 3, 2025
@oklemenz2 oklemenz2 removed the stale label Jan 3, 2025
@Caisi
Copy link

Caisi commented Jan 5, 2025

Hello, any update on this issue? I have a similar problem.
When I tested fix mentioned above, it helped.

When could we expect new patch version release?

BTW I found a workaround by setting cds.features.odata_new_adapter=false as described CAP documentation. Please note that the issue occurs only in CAP v8.

Thanks.

@oklemenz2
Copy link
Contributor

I will release on Tuesday morning.

@oklemenz2
Copy link
Contributor

1.14.0 is released: https://github.com/cap-js-community/odata-v2-adapter/releases/tag/v1.14.0
Please check.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants