i am not sure if this  elif  is correctly placed  it seems you want to raise the error below is net type is not vlan but it is aligned with if attributes is attr set net type so i guess you will hit it if net type is not set  not sure that this is what you want