Bug with nested parents

Consider the following code: I put three cubes with respective positions x=0,3 and 6. Without parenting, everything is OK. Then I add two lines at the end : cube3 child of cube2 and cube2 child of cube 1. It turns out that the position of cube3 has changed after declaring the cube2 is the parent of cube 3 : cube 3 has moved from x=6 to x=9 !

   import bpy






bpy.ops.object.delete() # suppress the initial blender cube 


# some colors to distinguish the cubes 


vert2=bpy.data.materials.new("vert2")
bleu=bpy.data.materials.new("bleu")
peche=bpy.data.materials.new("peche")
vert2.diffuse_color=(0,1,0.5)
bleu.diffuse_color=(0.2,0.2,5)
peche.diffuse_color=(2,0.819,0.35)






# I define the cube with colors 
bpy.ops.mesh.primitive_cube_add()
cube1=bpy.context.object
cube1.data.materials.append(vert2)


bpy.ops.mesh.primitive_cube_add()
cube2=bpy.context.object
cube2.location=[3,0,0]
cube2.data.materials.append(bleu)




bpy.ops.mesh.primitive_cube_add()
cube3=bpy.context.object
cube3.location=[6,0,0]
cube3.data.materials.append(peche)


# Now parenting 


cube3.parent=cube2
cube2.parent=cube1