python - rollback is not working in django using commit_manually -
i looking import data csv file. need atomic transaction.i using django version 1.5.1. not able revert transaction if exception occurs.
@transaction.commit_manually def import_user_csv(request): if request.method == 'post' , request.files.has_key('csv_file'): csv_file = request.files['csv_file'] try: i, row in enumerate(csv.reader(csv_file, delimiter=',')): if == 0: continue else: createduser, created = user.objects.get_or_create( username=row[0], full_name=row[1] ) _, userrolecreated = useroption.objects.get_or_create( user_id = createduser.id, user_role = "employee" ) except: transaction.rollback() print ("exception occured........") #raise else: transaction.commit()
Comments
Post a Comment