prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  general_create performes one unnecessary db lookup
  `Serializer.save()` returns the instance we want already. No need to fetch it again from the db.
  
  </issue>
  <code>
  [start of pulpcore/app/tasks/base.py]
  1 from django.db import transaction
  2 
  3 from pulpcore.app.apps import get_plugin_config
  4 from pulpcore.app.models import CreatedResource, PulpTemporaryFile
  5 from pulpcore.app.files import PulpTemporaryUploadedFile
  6 from pulpcore.plugin.models import MasterModel
  7 
  8 
  9 def general_create_from_temp_file(app_label, serializer_name, temp_file_pk, *args, **kwargs):
  10     """
  11     Create a model instance from contents stored in a temporary file.
  12 
  13     A task which executes this function takes the ownership of a temporary file and deletes it
  14     afterwards. This function calls the function general_create() to create a model instance.
  15     """
  16     temp_file = PulpTemporaryFile.objects.get(pk=temp_file_pk)
  17 
  18     data = kwargs.pop("data", {})
  19     data["file"] = PulpTemporaryUploadedFile.from_file(temp_file.file)
  20 
  21     general_create(app_label, serializer_name, data=data, *args, **kwargs)
  22     temp_file.delete()
  23 
  24 
  25 def general_create(app_label, serializer_name, *args, **kwargs):
  26     """
  27     Create a model instance.
  28 
  29     Raises:
  30         ValidationError: If the serializer is not valid
  31 
  32     """
  33     data = kwargs.pop("data", None)
  34     context = kwargs.pop("context", {})
  35     serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]
  36     serializer = serializer_class(data=data, context=context)
  37     serializer.is_valid(raise_exception=True)
  38     serializer.save()
  39     instance = serializer_class.Meta.model.objects.get(pk=serializer.instance.pk).cast()
  40     resource = CreatedResource(content_object=instance)
  41     resource.save()
  42 
  43 
  44 def general_update(instance_id, app_label, serializer_name, *args, **kwargs):
  45     """
  46     Update a model
  47 
  48     The model instance is identified using the app_label, id, and serializer name. The serializer is
  49     used to perform validation.
  50 
  51     Args:
  52         id (str): the id of the model
  53         app_label (str): the Django app label of the plugin that provides the model
  54         serializer_name (str): name of the serializer class for the model
  55         data (dict): dictionary whose keys represent the fields of the model and their corresponding
  56             values.
  57         partial (bool): When true, only the fields specified in the data dictionary are updated.
  58             When false, any fields missing from the data dictionary are assumed to be None and
  59             their values are updated as such.
  60 
  61     Raises:
  62         :class:`rest_framework.exceptions.ValidationError`: When serializer instance can't be saved
  63             due to validation error. This theoretically should never occur since validation is
  64             performed before the task is dispatched.
  65     """
  66     data = kwargs.pop("data", None)
  67     partial = kwargs.pop("partial", False)
  68     serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]
  69     instance = serializer_class.Meta.model.objects.get(pk=instance_id).cast()
  70     serializer = serializer_class(instance, data=data, partial=partial)
  71     serializer.is_valid(raise_exception=True)
  72     serializer.save()
  73 
  74 
  75 def general_delete(instance_id, app_label, serializer_name):
  76     """
  77     Delete a model
  78 
  79     The model instance is identified using the app_label, id, and serializer name.
  80 
  81     Args:
  82         id (str): the id of the model
  83         app_label (str): the Django app label of the plugin that provides the model
  84         serializer_name (str): name of the serializer class for the model
  85     """
  86     serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]
  87     instance = serializer_class.Meta.model.objects.get(pk=instance_id).cast()
  88     instance.delete()
  89 
  90 
  91 def general_multi_delete(instance_ids):
  92     """
  93     Delete a list of model instances in a transaction
  94 
  95     The model instances are identified using the id, app_label, and serializer_name.
  96 
  97     Args:
  98         instance_ids (list): List of tupels of id, app_label, serializer_name
  99     """
  100     instances = []
  101     for instance_id, app_label, serializer_name in instance_ids:
  102         serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]
  103         instance = serializer_class.Meta.model.objects.get(pk=instance_id)
  104         if isinstance(instance, MasterModel):
  105             instance = instance.cast()
  106         instances.append(instance)
  107     with transaction.atomic():
  108         for instance in instances:
  109             instance.delete()
  110
  [end of pulpcore/app/tasks/base.py]
  </code>
  
  I need you to solve this issue by generating a single patch file that I can apply directly to this repository using git apply. Please respond with a single patch file in the following format.
  <patch>
  diff --git a/file.py b/file.py
  --- a/file.py
  +++ b/file.py
  @@ -1,27 +1,35 @@
   def euclidean(a, b):
  -    while b:
  -        a, b = b, a % b
  -    return a
  +    if b == 0:
  +        return a
  +    return euclidean(b, a % b)
   
   
   def bresenham(x0, y0, x1, y1):
       points = []
       dx = abs(x1 - x0)
       dy = abs(y1 - y0)
  -    sx = 1 if x0 < x1 else -1
  -    sy = 1 if y0 < y1 else -1
  -    err = dx - dy
  +    x, y = x0, y0
  +    sx = -1 if x0 > x1 else 1
  +    sy = -1 if y0 > y1 else 1
   
  -    while True:
  -        points.append((x0, y0))
  -        if x0 == x1 and y0 == y1:
  -            break
  -        e2 = 2 * err
  -        if e2 > -dy:
  -            err -= dy
  -            x0 += sx
  -        if e2 < dx:
  -            err += dx
  -            y0 += sy
  +    if dx > dy:
  +        err = dx / 2.0
  +        while x != x1:
  +            points.append((x, y))
  +            err -= dy
  +            if err < 0:
  +                y += sy
  +                err += dx
  +            x += sx
  +    else:
  +        err = dy / 2.0
  +        while y != y1:
  +            points.append((x, y))
  +            err -= dx
  +            if err < 0:
  +                x += sx
  +                err += dy
  +            y += sy
  +
  +    points.append((x, y))
       return points
  
  </patch>
golden_diff: diff --git a/pulpcore/app/tasks/base.py b/pulpcore/app/tasks/base.py
  --- a/pulpcore/app/tasks/base.py
  +++ b/pulpcore/app/tasks/base.py
  @@ -35,8 +35,7 @@
       serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]
       serializer = serializer_class(data=data, context=context)
       serializer.is_valid(raise_exception=True)
  -    serializer.save()
  -    instance = serializer_class.Meta.model.objects.get(pk=serializer.instance.pk).cast()
  +    instance = serializer.save().cast()
       resource = CreatedResource(content_object=instance)
       resource.save()
  
verification_info: {"golden_diff": "diff --git a/pulpcore/app/tasks/base.py b/pulpcore/app/tasks/base.py\n--- a/pulpcore/app/tasks/base.py\n+++ b/pulpcore/app/tasks/base.py\n@@ -35,8 +35,7 @@\n     serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]\n     serializer = serializer_class(data=data, context=context)\n     serializer.is_valid(raise_exception=True)\n-    serializer.save()\n-    instance = serializer_class.Meta.model.objects.get(pk=serializer.instance.pk).cast()\n+    instance = serializer.save().cast()\n     resource = CreatedResource(content_object=instance)\n     resource.save()\n", "issue": "general_create performes one unnecessary db lookup\n`Serializer.save()` returns the instance we want already. No need to fetch it again from the db.\n", "before_files": [{"content": "from django.db import transaction\n\nfrom pulpcore.app.apps import get_plugin_config\nfrom pulpcore.app.models import CreatedResource, PulpTemporaryFile\nfrom pulpcore.app.files import PulpTemporaryUploadedFile\nfrom pulpcore.plugin.models import MasterModel\n\n\ndef general_create_from_temp_file(app_label, serializer_name, temp_file_pk, *args, **kwargs):\n    \"\"\"\n    Create a model instance from contents stored in a temporary file.\n\n    A task which executes this function takes the ownership of a temporary file and deletes it\n    afterwards. This function calls the function general_create() to create a model instance.\n    \"\"\"\n    temp_file = PulpTemporaryFile.objects.get(pk=temp_file_pk)\n\n    data = kwargs.pop(\"data\", {})\n    data[\"file\"] = PulpTemporaryUploadedFile.from_file(temp_file.file)\n\n    general_create(app_label, serializer_name, data=data, *args, **kwargs)\n    temp_file.delete()\n\n\ndef general_create(app_label, serializer_name, *args, **kwargs):\n    \"\"\"\n    Create a model instance.\n\n    Raises:\n        ValidationError: If the serializer is not valid\n\n    \"\"\"\n    data = kwargs.pop(\"data\", None)\n    context = kwargs.pop(\"context\", {})\n    serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]\n    serializer = serializer_class(data=data, context=context)\n    serializer.is_valid(raise_exception=True)\n    serializer.save()\n    instance = serializer_class.Meta.model.objects.get(pk=serializer.instance.pk).cast()\n    resource = CreatedResource(content_object=instance)\n    resource.save()\n\n\ndef general_update(instance_id, app_label, serializer_name, *args, **kwargs):\n    \"\"\"\n    Update a model\n\n    The model instance is identified using the app_label, id, and serializer name. The serializer is\n    used to perform validation.\n\n    Args:\n        id (str): the id of the model\n        app_label (str): the Django app label of the plugin that provides the model\n        serializer_name (str): name of the serializer class for the model\n        data (dict): dictionary whose keys represent the fields of the model and their corresponding\n            values.\n        partial (bool): When true, only the fields specified in the data dictionary are updated.\n            When false, any fields missing from the data dictionary are assumed to be None and\n            their values are updated as such.\n\n    Raises:\n        :class:`rest_framework.exceptions.ValidationError`: When serializer instance can't be saved\n            due to validation error. This theoretically should never occur since validation is\n            performed before the task is dispatched.\n    \"\"\"\n    data = kwargs.pop(\"data\", None)\n    partial = kwargs.pop(\"partial\", False)\n    serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]\n    instance = serializer_class.Meta.model.objects.get(pk=instance_id).cast()\n    serializer = serializer_class(instance, data=data, partial=partial)\n    serializer.is_valid(raise_exception=True)\n    serializer.save()\n\n\ndef general_delete(instance_id, app_label, serializer_name):\n    \"\"\"\n    Delete a model\n\n    The model instance is identified using the app_label, id, and serializer name.\n\n    Args:\n        id (str): the id of the model\n        app_label (str): the Django app label of the plugin that provides the model\n        serializer_name (str): name of the serializer class for the model\n    \"\"\"\n    serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]\n    instance = serializer_class.Meta.model.objects.get(pk=instance_id).cast()\n    instance.delete()\n\n\ndef general_multi_delete(instance_ids):\n    \"\"\"\n    Delete a list of model instances in a transaction\n\n    The model instances are identified using the id, app_label, and serializer_name.\n\n    Args:\n        instance_ids (list): List of tupels of id, app_label, serializer_name\n    \"\"\"\n    instances = []\n    for instance_id, app_label, serializer_name in instance_ids:\n        serializer_class = get_plugin_config(app_label).named_serializers[serializer_name]\n        instance = serializer_class.Meta.model.objects.get(pk=instance_id)\n        if isinstance(instance, MasterModel):\n            instance = instance.cast()\n        instances.append(instance)\n    with transaction.atomic():\n        for instance in instances:\n            instance.delete()\n", "path": "pulpcore/app/tasks/base.py"}]}