'FLASK TypeError: edit_user( got an unexpected keyword argument 'first_name' using MySql, Flask, with React Frontend

I'm having an issue with an update route in Flask, the error reads: "line 37, in update_user user = User.edit_user( TypeError: edit_user() got an unexpected keyword argument 'first_name'"

Here is the controller code:


    @app.route('/update/<int:id>', methods=['PUT'])
    def update_user(id):
        print("hello", id)
        user_data = request.get_json(id)
        # context = {
        #     {user}:
        #     {
        #     "first_name":request.json(['first_name']),
        #     "last_name":request.json(['last_name']),
        #     "location":request.json(['location']),
        #     "email":request.json(['email']),
        #     "password":request.json(['password']),
        #     }
        # }
        print("This is Context", user_data)
        user = User.edit_user(
            first_name= user_data['first_name'],
            last_name= user_data['last_name'],
            location= user_data['location'],
            email= user_data['email'],
            password= user_data['password'],
        )
        # user_save = User.save(context)
        print("aloha", user)
        return jsonify(user=user)

Here is the code from the model:


    class User:
        def __init__(self,data) -> None:
            self.id = data['id']
            self.first_name = data['first_name']
            self.last_name = data['last_name']
            self.email = data['email']
            self.location = data['location']
            self.password = data['password']
            self.created_at = data['created_at']
            self.updated_at = data['updated_at']
        #EDIT USER
        @classmethod
        def edit_user(cls,data):
            query = "UPDATE users SET first_name = %(first_name)s, last_name = %(last_name)s, email = %(email)s, updated_at = NOW() WHERE id = %(id)s;"
            return connectToMySQL(DB).query_db(query,data)

Lines 24 and 36 print but 45 does not. This leads me to believe the issue is with User.edit_user(). Previously I was passing user_data in and user was printing as False with a boolean error, but it was getting to the third print statement. Here is what that code looks like:


    @app.route('/update/<int:id>', methods=['PUT'])
    def update_user(id):
        print("hello", id)
        user_data = request.get_json(id)
        print("This is Context", user_data)
        user = User.edit_user(user_data)
        print("aloha", user)
        return jsonify(user=user)

Anyone have guidance on a solution here?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source