The example code does sets the parentID, so it does correctly attempts to have a parent/child relation.
order.orderId = app.nextValidOrderId
stopLossOrder.orderId = app.nextValidOrderId + 1
stopLossOrder.parentId = app.nextValidOrderId
I suspect the issue could be the use of both OrderType and orderType, in python you can dynamically add attributes in that way, but you should have only the expected orderType, what happens if you have both I don't know.? There is also an error on the limit price being a string (should be a float)
order = Order()
order.OrderType = "LMT";???? <<<<<
order.action = 'BUY'
order.totalQuantity = 3
order.orderType = 'LMT'????? <<<<<
order.lmtPrice = '21'??????? <<<<<
order.transmit = False