docstr: Bulk create tags and tagged objects
  ---
  post:
    summary: Get all objects associated with a tag
    parameters:
    - in: path
      schema:
        type: integer
      name: tag_id
    requestBody:
      description: Tag schema
      required: true
      content:
        application/json:
          schema:
            type: object
            properties:
              tags:
                description: list of tag names to add to object
                type: array
                items:
                  type: string
              objects_to_tag:
                description: list of object names to add to object
                type: array
                items:
                  type: array
    responses:
      200:
        description: Tag added to favorites
        content:
          application/json:
            schema:
              type: object
              properties:
                result:
                  type: object
      302:
        description: Redirects to the current digest
      400:
        $ref: '#/components/responses/400'
      401:
        $ref: '#/components/responses/401'
      404:
        $ref: '#/components/responses/404'
      500:
        $ref: '#/components/responses/500'
docstr_tok: ["Bulk","create","tags","and","tagged","objects","--","-","post",":","summary",":","Get","all","objects","associated","with","a","tag","parameters",":","-","in",":","path","schema",":","type",":","integer","name",":","tag_id","requestBody",":","description",":","Tag","schema","required",":","true","content",":","application\/json",":","schema",":","type",":","object","properties",":","tags",":","description",":","list","of","tag","names","to","add","to","object","type",":","array","items",":","type",":","string","objects_to_tag",":","description",":","list","of","object","names","to","add","to","object","type",":","array","items",":","type",":","array","responses",":","200",":","description",":","Tag","added","to","favorites","content",":","application\/json",":","schema",":","type",":","object","properties",":","result",":","type",":","object","302",":","description",":","Redirects","to","the","current","digest","400",":","$","ref",":","'","#","\/components\/responses\/400'","401",":","$","ref",":","'","#","\/components\/responses\/401'","404",":","$","ref",":","'","#","\/components\/responses\/404'","500",":","$","ref",":","'","#","\/components\/responses\/500","'"]
code: def bulk_create(self) -> Response:
      """Bulk create tags and tagged objects
      ---
      post:
        summary: Get all objects associated with a tag
        parameters:
        - in: path
          schema:
            type: integer
          name: tag_id
        requestBody:
          description: Tag schema
          required: true
          content:
            application/json:
              schema:
                type: object
                properties:
                  tags:
                    description: list of tag names to add to object
                    type: array
                    items:
                      type: string
                  objects_to_tag:
                    description: list of object names to add to object
                    type: array
                    items:
                      type: array
        responses:
          200:
            description: Tag added to favorites
            content:
              application/json:
                schema:
                  type: object
                  properties:
                    result:
                      type: object
          302:
            description: Redirects to the current digest
          400:
            $ref: '#/components/responses/400'
          401:
            $ref: '#/components/responses/401'
          404:
            $ref: '#/components/responses/404'
          500:
            $ref: '#/components/responses/500'
      """
      try:
          item = TagPostBulkSchema().load(request.json)
      except ValidationError as error:
          return self.response_400(message=error.messages)
      try:
          all_tagged_objects: set[tuple[str, int]] = set()
          all_skipped_tagged_objects: set[tuple[str, int]] = set()
          for tag in item.get("tags"):
              tagged_item: dict[str, Any] = self.add_model_schema.load(
                  {
                      "name": tag.get("name"),
                      "objects_to_tag": tag.get("objects_to_tag"),
                  }
              )
              (
                  objects_tagged,
                  objects_skipped,
              ) = CreateCustomTagWithRelationshipsCommand(
                  tagged_item, bulk_create=True
              ).run()
              all_tagged_objects = all_tagged_objects | objects_tagged
              all_skipped_tagged_objects = (
                  all_skipped_tagged_objects | objects_skipped
              )
          return self.response(
              200,
              result={
                  "objects_tagged": list(
                      all_tagged_objects - all_skipped_tagged_objects
                  ),
                  "objects_skipped": list(all_skipped_tagged_objects),
              },
          )
      except TagNotFoundError:
          return self.response_404()
      except TagInvalidError as ex:
          return self.response_422(message=ex.message)
  
imports: import logging
  from typing import Any
  from flask import request, Response
  from flask_appbuilder.api import expose, protect, rison, safe
  from flask_appbuilder.models.sqla.interface import SQLAInterface
  from marshmallow import ValidationError
  from superset.commands.tag.create import CreateCustomTagCommand, CreateCustomTagWithRelationshipsCommand
  from superset.commands.tag.delete import DeleteTaggedObjectCommand, DeleteTagsCommand
  from superset.commands.tag.exceptions import TagDeleteFailedError, TaggedObjectDeleteFailedError, TaggedObjectNotFoundError, TagInvalidError, TagNotFoundError, TagUpdateFailedError
  from superset.commands.tag.update import UpdateTagCommand
  from superset.constants import MODEL_API_RW_METHOD_PERMISSION_MAP, RouteMethod
  from superset.daos.tag import TagDAO
  from superset.exceptions import MissingUserContextException
  from superset.extensions import event_logger
  from superset.tags.models import ObjectType, Tag
  from superset.tags.schemas import delete_tags_schema, openapi_spec_methods_override, TaggedObjectEntityResponseSchema, TagGetResponseSchema, TagPostBulkSchema, TagPostSchema, TagPutSchema
  from superset.views.base_api import BaseSupersetModelRestApi, RelatedFieldFilter, statsd_metrics
  from superset.views.filters import BaseFilterRelatedUsers, FilterRelatedOwners
label_desc: Use image node_id 3 for calling the TagRestApi obj's underlying member method code with example usage: obj.bulk_create() and returns: self, self, self, self