_3S.CoDeSys.Core.Objects.InvalidProjectHandleException
Standard Error: The project handle 0 is invalid
Workaround:
When you do branch copy with checkout=False and then checkout the branch in a seperate line everything works. The issue seems to be that Codesys doesn't give back a proper handle when you do branch_copy with checkout=True.
This is mainly so that issue gets noted and resolved in a further Patch and that people with the same issue might have an easier time debugging their scripts.
With kind regards
Matthias Rudigier
👍
1
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Hi Matthias, thanks for writing this up so clearly — I ran into something very similar when I moved a build script from SP21 to SP22, and your two-step workaround is exactly what I ended up doing too.
My guess is that with checkout=True the branch switch closes and reopens the project behind the scenes, and the handle the call returns still points at the old instance, so it is already dead by the time the script touches it again. That would explain the 0 handle, and why splitting it into branch_copy with checkout=False followed by a separate checkout works fine — the second call resolves the project fresh in its new state.
One thing worth trying, if you have not already: after the branch_copy with checkout=True, fetch the project object again from the scripting session instead of reusing the one the call returned, and see whether that object is usable. If it is, that pretty much confirms the handle goes stale on the switch. And if you can reproduce it on a small test project, that makes it a lot easier to report — your post already has the key details, SP21 P3 worked and SP22 P3 fails with the exact exception, so a support ticket with the same text and a minimal script should be enough for them to reproduce it.
Until there is a patch I would stick with your workaround, it is the safer shape anyway. Just run that kind of branch-switching script on a copy of the project first, or at least with everything committed, so a half-finished switch cannot leave the working tree in a state you have to untangle by hand.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Since upgrading from V3.5 SP21 P3 to SP22 P3, this previously working scripted call fails:
project, current_branch = project.git.branch_copy(current_branch,new_branch_name,checkout=True)
Error:
_3S.CoDeSys.Core.Objects.InvalidProjectHandleException
Standard Error: The project handle 0 is invalid
Workaround:
When you do branch copy with checkout=False and then checkout the branch in a seperate line everything works. The issue seems to be that Codesys doesn't give back a proper handle when you do branch_copy with checkout=True.
This is mainly so that issue gets noted and resolved in a further Patch and that people with the same issue might have an easier time debugging their scripts.
With kind regards
Matthias Rudigier
more posts ...
Hi Matthias, thanks for writing this up so clearly — I ran into something very similar when I moved a build script from SP21 to SP22, and your two-step workaround is exactly what I ended up doing too.
My guess is that with checkout=True the branch switch closes and reopens the project behind the scenes, and the handle the call returns still points at the old instance, so it is already dead by the time the script touches it again. That would explain the 0 handle, and why splitting it into branch_copy with checkout=False followed by a separate checkout works fine — the second call resolves the project fresh in its new state.
One thing worth trying, if you have not already: after the branch_copy with checkout=True, fetch the project object again from the scripting session instead of reusing the one the call returned, and see whether that object is usable. If it is, that pretty much confirms the handle goes stale on the switch. And if you can reproduce it on a small test project, that makes it a lot easier to report — your post already has the key details, SP21 P3 worked and SP22 P3 fails with the exact exception, so a support ticket with the same text and a minimal script should be enough for them to reproduce it.
Until there is a patch I would stick with your workaround, it is the safer shape anyway. Just run that kind of branch-switching script on a copy of the project first, or at least with everything committed, so a half-finished switch cannot leave the working tree in a state you have to untangle by hand.