def put(self, pk):
        """Edit group
        ---
        put:
          parameters:
          - in: path
            schema:
              type: integer
            name: pk
          requestBody:
            description: Model schema
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/GroupPutSchema'
          responses:
            200:
              description: Group updated
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      result:
                        $ref: '#/components/schemas/GroupPutSchema'
            400:
              $ref: '#/components/responses/400'
            401:
              $ref: '#/components/responses/401'
            404:
              $ref: '#/components/responses/404'
            422:
              $ref: '#/components/responses/422'
            500:
              $ref: '#/components/responses/500'
        """
        try:
            item = self.edit_model_schema.load(request.json)
            model = self.datamodel.get(pk, self._base_filters)
            if not model:
                return self.response_404()

            roles = []
            users = []

            for key, value in item.items():
                if key == "roles":
                    roles = self._fetch_entities(Role, value)
                    missing_role_ids = set(value) - {r.id for r in roles}
                    if missing_role_ids:
                        return self.response_400(
                            message={
                                "roles": [
                                    (
                                        f"Role(s) with ID(s) {sorted(missing_role_ids)} "
                                        "do not exist."
                                    )
                                ]
                            }
                        )
                elif key == "users":
                    users = self._fetch_entities(User, value)
                    missing_user_ids = set(value) - {u.id for u in users}
                    if missing_user_ids:
                        return self.response_400(
                            message={
                                "users": [
                                    (
                                        f"User(s) with ID(s) {sorted(missing_user_ids)} "
                                        "do not exist."
                                    )
                                ]
                            }
                        )
                else:
                    setattr(model, key, value)

            if "roles" in item.keys():
                model.roles = roles
            if "users" in item.keys():
                model.users = users
            self.pre_update(model)
            self.datamodel.edit(model, raise_exception=True)
            return self.response(
                200,
                **{API_RESULT_RES_KEY: self.edit_model_schema.dump(item, many=False)},
            )

        except ValidationError as e:
            return self.response_400(message=e.messages)
        except IntegrityError as e:
            return self.response_422(message=str(e.orig))
Edit group
        ---
        put:
          parameters:
          - in: path
            schema:
              type: integer
            name: pk
          requestBody:
            description: Model schema
            required: true
            content:
              application/json:
                schema:
                  $ref: '#/components/schemas/GroupPutSchema'
          responses:
            200:
              description: Group updated
              content:
                application/json:
                  schema:
                    type: object
                    properties:
                      result:
                        $ref: '#/components/schemas/GroupPutSchema'
            400:
              $ref: '#/components/responses/400'
            401:
              $ref: '#/components/responses/401'
            404:
              $ref: '#/components/responses/404'
            422:
              $ref: '#/components/responses/422'
            500:
              $ref: '#/components/responses/500'
        
flask_appbuilder/security/sqla/apis/group/api.py