docstr: Update a database.
  ---
  put:
    summary: Change a database
    parameters:
    - in: path
      schema:
        type: integer
      name: pk
    requestBody:
      description: Database schema
      required: true
      content:
        application/json:
          schema:
            $ref: '#/components/schemas/{{self.__class__.__name__}}.put'
    responses:
      200:
        description: Database 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'
      403:
        $ref: '#/components/responses/403'
      404:
        $ref: '#/components/responses/404'
      422:
        $ref: '#/components/responses/422'
      500:
        $ref: '#/components/responses/500'
code: def put(self, pk: int) -> Response:
      """Update a database.
      ---
      put:
        summary: Change a database
        parameters:
        - in: path
          schema:
            type: integer
          name: pk
        requestBody:
          description: Database schema
          required: true
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/{{self.__class__.__name__}}.put'
        responses:
          200:
            description: Database 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'
          403:
            $ref: '#/components/responses/403'
          404:
            $ref: '#/components/responses/404'
          422:
            $ref: '#/components/responses/422'
          500:
            $ref: '#/components/responses/500'
      """
      try:
          item = self.edit_model_schema.load(request.json)
      # This validates custom Schema with custom validations
      except ValidationError as error:
          return self.response_400(message=error.messages)
      try:
          changed_model = UpdateDatabaseCommand(pk, item).run()
          # Return censored version for sqlalchemy URI
          item["sqlalchemy_uri"] = changed_model.sqlalchemy_uri
          if changed_model.parameters:
              item["parameters"] = changed_model.parameters
          # Return SSH Tunnel and hide passwords if any
          if item.get("ssh_tunnel"):
              item["ssh_tunnel"] = mask_password_info(
                  changed_model.ssh_tunnel
              )
          return self.response(200, id=changed_model.id, result=item)
      except DatabaseNotFoundError:
          return self.response_404()
      except DatabaseInvalidError as ex:
          return self.response_422(message=ex.normalized_messages())
      except DatabaseConnectionFailedError as ex:
          return self.response_422(message=str(ex))
      except DatabaseUpdateFailedError as ex:
          logger.error(
              "Error updating model %s: %s",
              self.__class__.__name__,
              str(ex),
              exc_info=True,
          )
          return self.response_422(message=str(ex))
      except SSHTunnelingNotEnabledError as ex:
          return self.response_400(message=str(ex))
  
imports: import json
  import logging
  from datetime import datetime
  from io import BytesIO
  from typing import Any, cast, Optional
  from zipfile import is_zipfile, ZipFile
  from flask import request, Response, send_file
  from flask_appbuilder.api import expose, protect, rison, safe
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from marshmallow import ValidationError
  from sqlalchemy.exc import NoSuchTableError, OperationalError, SQLAlchemyError
  from superset import app, event_logger
  from superset.commands.database.create import CreateDatabaseCommand
  from superset.commands.database.delete import DeleteDatabaseCommand
  from superset.commands.database.exceptions import DatabaseConnectionFailedError, DatabaseCreateFailedError, DatabaseDeleteDatasetsExistFailedError, DatabaseDeleteFailedError, DatabaseInvalidError, DatabaseNotFoundError, DatabaseTablesUnexpectedError, DatabaseUpdateFailedError, InvalidParametersError
  from superset.commands.database.export import ExportDatabasesCommand
  from superset.commands.database.importers.dispatcher import ImportDatabasesCommand
  from superset.commands.database.ssh_tunnel.delete import DeleteSSHTunnelCommand
  from superset.commands.database.ssh_tunnel.exceptions import SSHTunnelDeleteFailedError, SSHTunnelingNotEnabledError, SSHTunnelNotFoundError
  from superset.commands.database.tables import TablesDatabaseCommand
  from superset.commands.database.test_connection import TestConnectionDatabaseCommand
  from superset.commands.database.update import UpdateDatabaseCommand
  from superset.commands.database.validate import ValidateDatabaseParametersCommand
  from superset.commands.database.validate_sql import ValidateSQLCommand
  from superset.commands.importers.exceptions import IncorrectFormatError, NoValidFilesFoundError
  from superset.commands.importers.v1.utils import get_contents_from_bundle
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
  from superset.daos.database import DatabaseDAO
  from superset.databases.decorators import check_datasource_access
  from superset.databases.filters import DatabaseFilter, DatabaseUploadEnabledFilter
  from superset.databases.schemas import database_schemas_query_schema, database_tables_query_schema, DatabaseConnectionSchema, DatabaseFunctionNamesResponse, DatabasePostSchema, DatabasePutSchema, DatabaseRelatedObjectsResponse, DatabaseSchemaAccessForFileUploadResponse, DatabaseTablesResponse, DatabaseTestConnectionSchema, DatabaseValidateParametersSchema, get_export_ids_schema, openapi_spec_methods_override, SchemasResponseSchema, SelectStarResponseSchema, TableExtraMetadataResponseSchema, TableMetadataResponseSchema, ValidateSQLRequest, ValidateSQLResponse
  from superset.databases.utils import get_table_metadata
  from superset.db_engine_specs import get_available_engine_specs
  from superset.errors import ErrorLevel, SupersetError, SupersetErrorType
  from superset.exceptions import SupersetErrorsException, SupersetException
  from superset.extensions import security_manager
  from superset.models.core import Database
  from superset.superset_typing import FlaskResponse
  from superset.utils.core import error_msg_from_exception, parse_js_uri_path_item
  from superset.utils.ssh_tunnel import mask_password_info
  from superset.views.base import json_errors_response
  from superset.views.base_api import BaseSupersetModelRestApi, requires_form_data, requires_json, statsd_metrics
label_desc: Use image node_id 4 for calling the DatabaseRestApi obj's underlying member method code with example usage: obj.put(pk) and returns: self, self, self, self, self, self, self