Context becomes a Nonetype object when called by a custom panel I'm now debugging my code for 2 days and I can't find any solutions to my problem. 

I am building an add-on for my company and I need to create a Panel to call the new operator. 

The operator by himself works but when I call it with the Custom Panel it gives me an AttributeError : 'NoneType' object has no attribute 'data' on this function :

def parenting(parent,child):
    bpy.ops.object.mode_set(mode='EDIT')
    pbone = bpy.context.object.data.edit_bones['%s'%parent]
    cbone = bpy.context.object.data.edit_bones['%s'%child]

    pbone.select = True
    cbone.select = True
    bpy.context.selected_bones

    scn.update()

    cbone.parent = pbone


So I believe the class where I create the panel and call the operator has some issues

class LayoutDemoPanel(bpy.types.Panel):
    """Creates a Panel in the scene context of the properties editor"""
    bl_label = "Automation"
    bl_idname = "automation"
    bl_space_type = 'PROPERTIES'
    bl_region_type = 'WINDOW'
    bl_context = "world"

    def draw(self, context):
        layout = self.layout
        #scene = bpy.context.scene
        layout.prop(bpy.context.scene, 'MyWB')
        layout.prop(bpy.context.scene, 'MyT')
        layout.prop(bpy.context.scene, 'Myd')
        col = layout.column()
        col.prop(bpy.context.scene, 'Car_path')
        col.prop(bpy.context.scene, 'Wheel_path')
        row = layout.row()
        row.label(text = "Environment")
        row.operator(operator = "dh.autom")
        return {"FINISHED"}

def register():
    bpy.utils.register_class(AutomationOperator) 
    bpy.utils.register_class(LayoutDemoPanel)



def unregister():
    bpy.utils.unregister_class(AutomationOperator) 
    bpy.utils.unregister_class(LayoutDemoPanel)

#if __name__ == "__main__":
bpy.utils.register_module(__name__)


If any one has any idea?
I resolved my problem finally, 
i'm just going to share the solution in case of someone has the same issue

the error was coming from the definition of the parent bone and the child one. Because I am in edit mode, I have to define them in the armature and not in the object. 

So instead of

pbone = bpy.context.object.data.edit_bones['%s'%parent]


the correct code is 

amt = bpy.data.armatures['PLATFORMAmt']    
pbone = amt.edit_bones['%s'%parent]