OrchardCore icon indicating copy to clipboard operation
OrchardCore copied to clipboard

Fix the BUG that CorrelationId is overwritten

Open hyzx86 opened this issue 4 years ago • 17 comments

The correlationId with the workflow will be assigned after the content is created (step1) but ,when a content item is created in a workflow using a Create Content Activity , the contentItemId of the new content overrides the correlationId of the workflow . ( step2)

Causes step3 and step4 never to trigger

image in step 2

image

hyzx86 avatar Dec 28 '21 10:12 hyzx86

Hi @Skrypt ,Can you help review this PR?

hyzx86 avatar Dec 29 '21 01:12 hyzx86

Hi @Skrypt Is there anything wrong with this change?

hyzx86 avatar Feb 24 '22 10:02 hyzx86

@hishamco Done.

hyzx86 avatar Feb 25 '22 01:02 hyzx86

Why the build failed?

hishamco avatar Feb 25 '22 05:02 hishamco

I re-run the jobs, the build is pass

hishamco avatar Feb 25 '22 07:02 hishamco

Not sure I agree with this one, it fixes some scenarios but breaks other ones, e.g. after the execution of a RetrieveContentTask we may want (through the correlationId) to be in sync with the retrieved contentItemId even if an existing correlationId is already set. For other scenarios we have e.g. the Set Output and Set Property activities allowing to set and then retrieve a previous correlationId

For your scenario we have the oob User Task activity that halts the workflow until the user execute an action on a content item, in the activity settings you can define the action and the user role that can do the action, here the action could be named e.g. Approve, in that case if you edit the related content item you will see an Approve button that you will be able to click if you have the permission.

jtkech avatar Feb 25 '22 20:02 jtkech

Hi @jtkech ,

after the execution of a RetrieveContentTask we may want (through the correlationId) to be in sync with the retrieved contentItemId even if an existing correlationId is already set.

I think this operation is a little too subtle, and no one knows it without documentation and without looking at the code As a workflow node, it should not affect the global properties of the entire workflow, it should only take the input and output the appropriate content, Unless it is the Task explicitly to update correlationId, Otherwise, the global properties of the workflow should not be modified implicitly within it, And they're just a Task not an Event we can get all the information through LastResult

In addition, the approval I refer to is not just approval through OC interface, if I want users to approve by email. Some dynamic scripts cannot be executed

hyzx86 avatar Feb 26 '22 04:02 hyzx86

@hyzx86

Yes I understand your use case ;) But still not sure that the correlationId should always stay the same for the whole WF execution, particularly after the retrieve content task, maybe an activity option to not override an existing correlationId.

Maybe here your signal_url would need to be correlated with the global WorkflowId, not the ContentItemId, hmm can be done by inserting between step 1 and 2 a correlate task that just set the correlationId to null, in that case I think that the signal_url token will use the workflowId instead.

Anyway I don't want to block your PR, so I will let others triage it.

jtkech avatar Feb 26 '22 07:02 jtkech

I remember that in the signal task if the corrlationID is empty, it creates a new ID instead of using the workflow ID directly. The workflow ID may not exist because the signal task can also start the workflow (too long ago to remember).

This approval process is just an example. If I need multiple levels of approval, I need to reset correlationid before each approval task.

hyzx86 avatar Feb 26 '22 11:02 hyzx86

@jtkech I will label this as dontmerge and let you decide how this should go, or let the others triage it

hishamco avatar Feb 26 '22 16:02 hishamco

I remember that in the signal task if the corrlationID is empty, it creates a new ID instead of using the workflow ID directly.

There is no signal task, only a signal event, and we can generate a signal url through a SignalMethodProvider or a signal_url liquid filter (as here), that targets the HttpWorkflowController that will trigger the related workflow, in both ways to generate the url if CorrelationId is null or empty the WorkflowId is used in the payload.

The workflow ID may not exist because the signal task can also start the workflow

I don't think so, on each NewWorkflow() a new WorkflowId is generated.

Just tried to add just before step 2 a CorrelateTask with no value that I named "Decorrelate", yes when we edit the halted instance we still see the CorrelationId set to the 2nd contentItemId, but in the approval page the signal_url was already generated with the WorkflowId, then when I clicked on an Approve/Reject link the WF was resumed.

jtkech avatar Feb 26 '22 21:02 jtkech

Is this something you'd like to revisit any time soon @hyzx86 or should we close?

Piedone avatar Jan 28 '24 23:01 Piedone

Is this something you'd like to revisit any time soon @hyzx86 or should we close?

Hi @Piedone , Combined with the problems mentioned by JT, I don't think there will be any problems with my PR

The existing code will always update CorrelationId, I'm just adding a check

hyzx86 avatar Jan 29 '24 07:01 hyzx86

OK then! @hishamco @Skrypt you've reviewed this previously, please check this out if you still approve. Also, Hisham you added dontmerge, please check that's still applicable.

Piedone avatar Jan 29 '24 20:01 Piedone

You can always still update the correlationId by using different methods as mentioned by @hyzx86 and J-T. Maybe it can potentially break someone's workflow but that's how it is when you do a change in these ... document the change in the release notes.

Skrypt avatar Jan 30 '24 15:01 Skrypt

@Skrypt , Maybe I can add a script function to this PR Just like setCorrelationId(string) ?

hyzx86 avatar Jan 31 '24 03:01 hyzx86

Yeah, maybe instead of setting it from server side we could have a script that would affect it. That would be non-breaking.

Skrypt avatar Jan 31 '24 14:01 Skrypt

Would you like to get back to this, @hyzx86?

Piedone avatar Mar 13 '24 17:03 Piedone

Would you like to get back to this, @hyzx86?

Well, what do I do now

hyzx86 avatar Mar 13 '24 17:03 hyzx86

What you have discussed last:

image

Piedone avatar Mar 13 '24 17:03 Piedone

@Skrypt can you please elaborate on why do you think this needs triage? What should we be mindful of during the triage?

Piedone avatar Apr 21 '24 19:04 Piedone

Waiting on @hyzx86 to know if he implemented what I suggested. If it is done then we need to review/test that code again to make sure it is fine.

It can be triaged on next thursday meeting and decided if it will be merged for current release or not.

Skrypt avatar Apr 22 '24 13:04 Skrypt

Since this is a non-breaking change (right?) why wouldn't we merge if it otherwise looks good?

Piedone avatar Apr 22 '24 13:04 Piedone

Yeah, he seems to have added the method. I'd say, let's merge it.

Skrypt avatar Apr 22 '24 14:04 Skrypt

OK, please approve, and you @hishamco (since you reviewed previously).

Piedone avatar Apr 22 '24 15:04 Piedone