Please answer the following questions for yourself before submitting an issue.
The requestID of a call is null on the first call to a service. On next calls it has a value.
requestID should have the same value.
Run, the snippet below, check the logs.
A null value is logged on the first call, but it has a different value on the second call.
See the code at https://codesandbox.io/s/moleculer-sample-2mz7d
I have a service which is reusing data for every request. I need the requestID to be valued every time I call the service within the same request, especially for tests.
I found that by triggering the request.id getter in the first parent service, the requestID is always valued in nested calls. To see the workaround, just replace the line 18 of the code above with:
ctx.id && (await ctx.call("called.action"));
Alternatively, I could use the parentID as a placeholder if requestID is null, correct?
null 'f19bf0e5-be19-4029-965b-55749bc78774'
f19bf0e5-be19-4029-965b-55749bc78774 f19bf0e5-be19-4029-965b-55749bc78774
the first line shows the issue.
Something weird is happening over here :confused:
Tried to debug to see what's happening and just hovering twice over ctx sets the requestID.
Hover the first time and it's null, hover the second time and it's set...

ctx.id is a getter, so it's value will be generated only if need. Generating UUID is an expensive operation, so it will generate only if it's read.
Thanks @icebob that clears things
I think the only solution if we convert requestID to getter/setter (like id) and if not set manually, we should set from ctx.id
@icebob I think the issue is here: https://github.com/moleculerjs/moleculer/blob/a0b5d9989cd0e4553cc160635f0895c86d1d2ddb/src/context.js#L122
On the first call the getter is triggered by the called service after the requestID computation. So probably it could be fixed by moving the parentID setup before the requestID.
By the way, this code would work only when the parent and the child are referencing the same object, which means that it works only if the services are local, correct?