Arbitrary parenting

I have no idea what this is about. I’m working on my custom rig script. Last thing i did was creating the deform bone chain for the leg. Now i want to parent the chain:

arm ="Armature", armData)
thigh_blend ="thigh.blend")
thigh01_def ="thigh01.def")

tigh01_def.parent = thigh_blend

I know it works cause i parented all the other chains that way, but for whatever reason when i execute the script, thigh01_def gets parented arbitrary to another bone. It changes everytime i execute it. Sometimes it crashes as well. So i thought maybe the scene was corupt in any way so execute the script in a new scene but that didnt helped neither. However I can parent the bone manually

Whats going on here?

The bone i tried to parent to had constraints applied. so by parenting the bones before applying the constraints to the parent, seems to work. Still, isnt it strange? Why would a constrained bone cause such a behaviour?