prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Custom field date-type objects AssertionError in GraphQL
  <!--
      NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.
  
      This form is only for reporting reproducible bugs. If you need assistance
      with Nautobot installation, or if you have a general question, please start a
      discussion instead: https://github.com/nautobot/nautobot/discussions
  
      Please describe the environment in which you are running Nautobot. Be sure
      that you are running an unmodified instance of the latest stable release
      before submitting a bug report, and that any plugins have been disabled.
  -->
  ### Environment
  * Nautobot version (Docker tag too if applicable): 1.5.17b1, also tested in 1.5.8
  * Python version: 3.9
  * Database platform, version: psql 13.10
  * Middleware(s): None
  
  <!--
      Describe in detail the exact steps that someone else can take to reproduce
      this bug using the current stable release of Nautobot. Begin with the
      creation of any necessary database objects and call out every operation
      being performed explicitly. If reporting a bug in the REST API, be sure to
      reconstruct the raw HTTP request(s) being made: Don't rely on a client
      library such as pynautobot.
  -->
  ### Steps to Reproduce
  1. Create a [custom field object](https://demo.nautobot.com/extras/custom-fields/last_backup/?tab=main) for the Device type template with the type as Date
  2. Set a date on a [device](https://demo.nautobot.com/dcim/devices/4d7aecac-addd-4f3c-8efc-e102872b54e5/?tab=main) in YYYY-MM-DD iso8601 format
  3. You have to restart nautobot-server; we may need a post_save signal event for this as well, which would be a separate issue if so
  4. Using GraphQL attempt to retrieve the value of this field from a device
  `
  {
    devices (name: "ams01-dist-01") {
      name,
      cf_last_backup
    }
  }
  `
  
  <!-- What did you expect to happen? -->
  ### Expected Behavior
  Query to return the value of the Date
  
  <!-- What happened instead? -->
  ### Observed Behavior
  * GrapQL returns `"message": "Received not compatible date \"'2023-04-26'\""`
  * stdout from nautobot-server gets an exception
  
  `[27/Apr/2023 17:20:01] "POST /graphql/ HTTP/1.1" 200 4437611
  Traceback (most recent call last):
    File "/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphql/execution/executor.py", line 480, in complete_value_catching_error
      completed = complete_value(
    File "/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphql/execution/executor.py", line 563, in complete_value
      return complete_leaf_value(return_type, path, result)
    File "/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphql/execution/executor.py", line 626, in complete_leaf_value
      serialized_result = return_type.serialize(result)
    File "/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphene/types/datetime.py", line 23, in serialize
      assert isinstance(
  AssertionError: Received not compatible date "'2023-04-26'"`
  
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `nautobot/core/graphql/types.py`
  Content:
  ```
  1 import datetime
  2 
  3 from django.contrib.contenttypes.models import ContentType
  4 import graphene
  5 import graphene_django_optimizer as gql_optimizer
  6 
  7 
  8 class OptimizedNautobotObjectType(gql_optimizer.OptimizedDjangoObjectType):
  9     url = graphene.String()
  10 
  11     def resolve_url(self, info):
  12         return self.get_absolute_url(api=True)
  13 
  14     class Meta:
  15         abstract = True
  16 
  17 
  18 class ContentTypeType(OptimizedNautobotObjectType):
  19     """
  20     Graphene-Django object type for ContentType records.
  21 
  22     Needed because ContentType is a built-in model, not one that we own and can auto-generate types for.
  23     """
  24 
  25     class Meta:
  26         model = ContentType
  27 
  28 
  29 class DateType(graphene.Date):
  30     """
  31     Overriding the default serialize method from https://github.com/graphql-python/graphene/blob/master/graphene/types/datetime.py
  32     to handle the case where the date object is passed as a str object.
  33     """
  34 
  35     @staticmethod
  36     def serialize(date):
  37         if isinstance(date, datetime.datetime):
  38             date = date.date()
  39             return date.isoformat()
  40         elif isinstance(date, str):
  41             return date
  42         else:
  43             raise AssertionError(f'Received not compatible date "{date!r}"')
  44 
  45 
  46 class JSON(graphene.Scalar):
  47     @staticmethod
  48     def serialize_data(dt):
  49         return dt
  50 
  51     serialize = serialize_data
  52     parse_value = serialize_data
  53     parse_literal = serialize_data
  54
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/nautobot/core/graphql/types.py b/nautobot/core/graphql/types.py
  --- a/nautobot/core/graphql/types.py
  +++ b/nautobot/core/graphql/types.py
  @@ -3,6 +3,7 @@
   from django.contrib.contenttypes.models import ContentType
   import graphene
   import graphene_django_optimizer as gql_optimizer
  +from graphql import GraphQLError
   
   
   class OptimizedNautobotObjectType(gql_optimizer.OptimizedDjangoObjectType):
  @@ -37,10 +38,12 @@
           if isinstance(date, datetime.datetime):
               date = date.date()
               return date.isoformat()
  +        elif isinstance(date, datetime.date):
  +            return date.isoformat()
           elif isinstance(date, str):
               return date
           else:
  -            raise AssertionError(f'Received not compatible date "{date!r}"')
  +            raise GraphQLError(f'Received not compatible date "{date!r}"')
   
   
   class JSON(graphene.Scalar):
  
verification_info: {"golden_diff": "diff --git a/nautobot/core/graphql/types.py b/nautobot/core/graphql/types.py\n--- a/nautobot/core/graphql/types.py\n+++ b/nautobot/core/graphql/types.py\n@@ -3,6 +3,7 @@\n from django.contrib.contenttypes.models import ContentType\n import graphene\n import graphene_django_optimizer as gql_optimizer\n+from graphql import GraphQLError\n \n \n class OptimizedNautobotObjectType(gql_optimizer.OptimizedDjangoObjectType):\n@@ -37,10 +38,12 @@\n         if isinstance(date, datetime.datetime):\n             date = date.date()\n             return date.isoformat()\n+        elif isinstance(date, datetime.date):\n+            return date.isoformat()\n         elif isinstance(date, str):\n             return date\n         else:\n-            raise AssertionError(f'Received not compatible date \"{date!r}\"')\n+            raise GraphQLError(f'Received not compatible date \"{date!r}\"')\n \n \n class JSON(graphene.Scalar):\n", "issue": "Custom field date-type objects AssertionError in GraphQL\n<!--\r\n    NOTE: IF YOUR ISSUE DOES NOT FOLLOW THIS TEMPLATE, IT WILL BE CLOSED.\r\n\r\n    This form is only for reporting reproducible bugs. If you need assistance\r\n    with Nautobot installation, or if you have a general question, please start a\r\n    discussion instead: https://github.com/nautobot/nautobot/discussions\r\n\r\n    Please describe the environment in which you are running Nautobot. Be sure\r\n    that you are running an unmodified instance of the latest stable release\r\n    before submitting a bug report, and that any plugins have been disabled.\r\n-->\r\n### Environment\r\n* Nautobot version (Docker tag too if applicable): 1.5.17b1, also tested in 1.5.8\r\n* Python version: 3.9\r\n* Database platform, version: psql 13.10\r\n* Middleware(s): None\r\n\r\n<!--\r\n    Describe in detail the exact steps that someone else can take to reproduce\r\n    this bug using the current stable release of Nautobot. Begin with the\r\n    creation of any necessary database objects and call out every operation\r\n    being performed explicitly. If reporting a bug in the REST API, be sure to\r\n    reconstruct the raw HTTP request(s) being made: Don't rely on a client\r\n    library such as pynautobot.\r\n-->\r\n### Steps to Reproduce\r\n1. Create a [custom field object](https://demo.nautobot.com/extras/custom-fields/last_backup/?tab=main) for the Device type template with the type as Date\r\n2. Set a date on a [device](https://demo.nautobot.com/dcim/devices/4d7aecac-addd-4f3c-8efc-e102872b54e5/?tab=main) in YYYY-MM-DD iso8601 format\r\n3. You have to restart nautobot-server; we may need a post_save signal event for this as well, which would be a separate issue if so\r\n4. Using GraphQL attempt to retrieve the value of this field from a device\r\n`\r\n{\r\n  devices (name: \"ams01-dist-01\") {\r\n    name,\r\n    cf_last_backup\r\n  }\r\n}\r\n`\r\n\r\n<!-- What did you expect to happen? -->\r\n### Expected Behavior\r\nQuery to return the value of the Date\r\n\r\n<!-- What happened instead? -->\r\n### Observed Behavior\r\n* GrapQL returns `\"message\": \"Received not compatible date \\\"'2023-04-26'\\\"\"`\r\n* stdout from nautobot-server gets an exception\r\n\r\n`[27/Apr/2023 17:20:01] \"POST /graphql/ HTTP/1.1\" 200 4437611\r\nTraceback (most recent call last):\r\n  File \"/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphql/execution/executor.py\", line 480, in complete_value_catching_error\r\n    completed = complete_value(\r\n  File \"/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphql/execution/executor.py\", line 563, in complete_value\r\n    return complete_leaf_value(return_type, path, result)\r\n  File \"/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphql/execution/executor.py\", line 626, in complete_leaf_value\r\n    serialized_result = return_type.serialize(result)\r\n  File \"/home/meganerd/.cache/pypoetry/virtualenvs/nautobot-Sgl-QJQc-py3.9/lib/python3.9/site-packages/graphene/types/datetime.py\", line 23, in serialize\r\n    assert isinstance(\r\nAssertionError: Received not compatible date \"'2023-04-26'\"`\r\n\r\n\n", "before_files": [{"content": "import datetime\n\nfrom django.contrib.contenttypes.models import ContentType\nimport graphene\nimport graphene_django_optimizer as gql_optimizer\n\n\nclass OptimizedNautobotObjectType(gql_optimizer.OptimizedDjangoObjectType):\n    url = graphene.String()\n\n    def resolve_url(self, info):\n        return self.get_absolute_url(api=True)\n\n    class Meta:\n        abstract = True\n\n\nclass ContentTypeType(OptimizedNautobotObjectType):\n    \"\"\"\n    Graphene-Django object type for ContentType records.\n\n    Needed because ContentType is a built-in model, not one that we own and can auto-generate types for.\n    \"\"\"\n\n    class Meta:\n        model = ContentType\n\n\nclass DateType(graphene.Date):\n    \"\"\"\n    Overriding the default serialize method from https://github.com/graphql-python/graphene/blob/master/graphene/types/datetime.py\n    to handle the case where the date object is passed as a str object.\n    \"\"\"\n\n    @staticmethod\n    def serialize(date):\n        if isinstance(date, datetime.datetime):\n            date = date.date()\n            return date.isoformat()\n        elif isinstance(date, str):\n            return date\n        else:\n            raise AssertionError(f'Received not compatible date \"{date!r}\"')\n\n\nclass JSON(graphene.Scalar):\n    @staticmethod\n    def serialize_data(dt):\n        return dt\n\n    serialize = serialize_data\n    parse_value = serialize_data\n    parse_literal = serialize_data\n", "path": "nautobot/core/graphql/types.py"}], "after_files": [{"content": "import datetime\n\nfrom django.contrib.contenttypes.models import ContentType\nimport graphene\nimport graphene_django_optimizer as gql_optimizer\nfrom graphql import GraphQLError\n\n\nclass OptimizedNautobotObjectType(gql_optimizer.OptimizedDjangoObjectType):\n    url = graphene.String()\n\n    def resolve_url(self, info):\n        return self.get_absolute_url(api=True)\n\n    class Meta:\n        abstract = True\n\n\nclass ContentTypeType(OptimizedNautobotObjectType):\n    \"\"\"\n    Graphene-Django object type for ContentType records.\n\n    Needed because ContentType is a built-in model, not one that we own and can auto-generate types for.\n    \"\"\"\n\n    class Meta:\n        model = ContentType\n\n\nclass DateType(graphene.Date):\n    \"\"\"\n    Overriding the default serialize method from https://github.com/graphql-python/graphene/blob/master/graphene/types/datetime.py\n    to handle the case where the date object is passed as a str object.\n    \"\"\"\n\n    @staticmethod\n    def serialize(date):\n        if isinstance(date, datetime.datetime):\n            date = date.date()\n            return date.isoformat()\n        elif isinstance(date, datetime.date):\n            return date.isoformat()\n        elif isinstance(date, str):\n            return date\n        else:\n            raise GraphQLError(f'Received not compatible date \"{date!r}\"')\n\n\nclass JSON(graphene.Scalar):\n    @staticmethod\n    def serialize_data(dt):\n        return dt\n\n    serialize = serialize_data\n    parse_value = serialize_data\n    parse_literal = serialize_data\n", "path": "nautobot/core/graphql/types.py"}]}