docstr: Update an annotation.
  ---
  put:
    summary: Update an annotation
    parameters:
    - in: path
      schema:
        type: integer
      name: pk
      description: The annotation layer pk for this annotation
    - in: path
      schema:
        type: integer
      name: annotation_id
      description: The annotation pk for this annotation
    requestBody:
      description: Annotation schema
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/{{self.__class__.__name__}}.put'
    responses:
      200:
        description: Annotation changed
        content:
          application/json:
            schema:
              type: object
              properties:
                id:
                  type: number
                result:
                  $ref: '#/components/schemas/{{self.__class__.__name__}}.put'
      400:
        $ref: '#/components/responses/400'
      401:
        $ref: '#/components/responses/401'
      404:
        $ref: '#/components/responses/404'
      500:
        $ref: '#/components/responses/500'
docstr_tok: ["Update","an","annotation",".","--","-","put",":","summary",":","Update","an","annotation","parameters",":","-","in",":","path","schema",":","type",":","integer","name",":","pk","description",":","The","annotation","layer","pk","for","this","annotation","-","in",":","path","schema",":","type",":","integer","name",":","annotation_id","description",":","The","annotation","pk","for","this","annotation","requestBody",":","description",":","Annotation","schema","required",":","true","content",":","application\/json",":","schema",":","$","ref",":","'","#","\/components\/schemas\/","{","{","self.__class__.__name__","}","}",".put'","responses",":","200",":","description",":","Annotation","changed","content",":","application\/json",":","schema",":","type",":","object","properties",":","id",":","type",":","number","result",":","$","ref",":","'","#","\/components\/schemas\/","{","{","self.__class__.__name__","}","}",".put'","400",":","$","ref",":","'","#","\/components\/responses\/400'","401",":","$","ref",":","'","#","\/components\/responses\/401'","404",":","$","ref",":","'","#","\/components\/responses\/404'","500",":","$","ref",":","'","#","\/components\/responses\/500","'"]
code: def put(  # pylint: disable=arguments-differ
      self, pk: int, annotation_id: int
  ) -> Response:
      """Update an annotation.
      ---
      put:
        summary: Update an annotation
        parameters:
        - in: path
          schema:
            type: integer
          name: pk
          description: The annotation layer pk for this annotation
        - in: path
          schema:
            type: integer
          name: annotation_id
          description: The annotation pk for this annotation
        requestBody:
          description: Annotation schema
          required: true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/{{self.__class__.__name__}}.put'
        responses:
          200:
            description: Annotation changed
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    id:
                      type: number
                    result:
                      $ref: '#/components/schemas/{{self.__class__.__name__}}.put'
          400:
            $ref: '#/components/responses/400'
          401:
            $ref: '#/components/responses/401'
          404:
            $ref: '#/components/responses/404'
          500:
            $ref: '#/components/responses/500'
      """
      try:
          item = self.edit_model_schema.load(request.json)
          item["layer"] = pk
      # This validates custom Schema with custom validations
      except ValidationError as error:
          return self.response_400(message=error.messages)
      try:
          new_model = UpdateAnnotationCommand(annotation_id, item).run()
          return self.response(200, id=new_model.id, result=item)
      except (AnnotationNotFoundError, AnnotationLayerNotFoundError):
          return self.response_404()
      except AnnotationInvalidError as ex:
          return self.response_422(message=ex.normalized_messages())
      except AnnotationUpdateFailedError as ex:
          logger.error(
              "Error updating annotation %s: %s",
              self.__class__.__name__,
              str(ex),
              exc_info=True,
          )
          return self.response_422(message=str(ex))
  
imports: import logging
  from typing import Any
  from flask import request, Response
  from flask_appbuilder.api import expose, permission_name, protect, rison, safe
  from flask_appbuilder.api.schemas import get_item_schema, get_list_schema
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from flask_babel import ngettext
  from marshmallow import ValidationError
  from superset.annotation_layers.annotations.filters import AnnotationAllTextFilter
  from superset.annotation_layers.annotations.schemas import AnnotationPostSchema, AnnotationPutSchema, get_delete_ids_schema, openapi_spec_methods_override
  from superset.commands.annotation_layer.annotation.create import CreateAnnotationCommand
  from superset.commands.annotation_layer.annotation.delete import DeleteAnnotationCommand
  from superset.commands.annotation_layer.annotation.exceptions import AnnotationCreateFailedError, AnnotationDeleteFailedError, AnnotationInvalidError, AnnotationNotFoundError, AnnotationUpdateFailedError
  from superset.commands.annotation_layer.annotation.update import UpdateAnnotationCommand
  from superset.commands.annotation_layer.exceptions import AnnotationLayerNotFoundError
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
  from superset.models.annotations import Annotation
  from superset.views.base_api import BaseSupersetModelRestApi, requires_json, statsd_metrics
label_desc: Use image node_id 5 for calling the AnnotationRestApi obj's underlying member method code with example usage: obj.put(pk, annotation_id) and returns: self, self, self, self, self