Как создать правильный запрос и исправить ошибку 422 ERROR - PullRequest
0 голосов
/ 18 февраля 2019

Я пытаюсь обновить данные в моей базе данных. Все в порядке, но когда я добавляю @ blp.arguments (UserSchema) и данные к моему запросу, я получаю 422 Ошибка (422 НЕИЗБЕЖНАЯ СУЩНОСТЬ) Не могли бы вы помочь мне исправить это?Вот мой код

@api.definition("User")
class UserSchema(StrictSchema):
    email = fields.String(required=True, description="The email of the user")
    description = fields.String(required=True, description="The full name of the user")





@blp.route("project/<int:project_id>", methods=["PUT"])
class Project(MethodView):
    # pylint: disable=no-self-use
    @login_required
    @blp.doc(
        parameters=[
        #{"name": "project_id", "in": "path", "description": "The ID of the user"},
        #{"name": "parent_id", "in": "body", "description": "The project description"},
        {"name": "email", "in": "body", "description": "The project code"},
        {"name": "description", "in": "body", "description": "The project description"},

        #{"name": "patients", "in": "body", "description": "The project description"},
    ]
)
    @blp.arguments(UserSchema)
    @blp.response(ProjectsSchema)
    def put(self, user: dict) -> ProjectsSchema:
        """Update a user
        ---
        :param user: The user data from request body
        :param project_id: The ID of the user being looked up
        :return:
        """
        print(user)
        try:
            query = db.session.query(ProjectModel).join(UserProject).filter(UserProject.user_id == current_user.id)
            found_project = query.filter(ProjectModel.project_id == 7).first()#project_id).first()
            found_project.description="description"
            db.session.commit()

        return found_project

А вот файл, где я вызываю метод put

def test_update_project(test_client):
    projects, _, headers = setup_projects(1)
    data = {"email": "new_email@test.com", "description": "New Fullname"}
    res = test_client.put(f"v2/project/{projects[0].project_id}", data=json.dumps(data), headers=headers)
    assert res.status_code == 200

Как я уже говорил, все будет правильно, пока я не добавлю @ blp.arguments (UserSchema)и данные = json.dumps (данные).В моей трассировке я вижу ошибку Нетип-объект не имеет определения атрибута

...