Please mention what is the error you received?
Problem is that you use the pragma to create a separate session. The shipment is only created in your session and since it is not yet committed it is not seen by the other session you start in the event.
You are creating a new session to avoid the mutating table error since you want to update the same table the event is triggering on.
It is impossible to do this directly in the event. It is only possible if you instead post a background job in the event that then executes after your session is ready.
Read more here:
I’m not sure if that solves the issue for your business needs but it might.