prompt: You will be provided with a partial code base and an issue statement explaining a problem to resolve.
  <issue>
  deficiency in new webhook implementation
  <!--
      Before opening a new issue, please search through the existing issues to
      see if your topic has already been addressed. Note that you may need to
      remove the "is:open" filter from the search bar to include closed issues.
  
      Check the appropriate type for your issue below by placing an x between the
      brackets. For assistance with installation issues, or for any other issues
      other than those listed below, please raise your topic for discussion on
      our mailing list:
  
          https://groups.google.com/forum/#!forum/netbox-discuss
  
      Please note that issues which do not fall under any of the below categories
      will be closed. Due to an excessive backlog of feature requests, we are
      not currently accepting any proposals which extend NetBox's feature scope.
  
      Do not prepend any sort of tag to your issue's title. An administrator will
      review your issue and assign labels as appropriate.
  --->
  ### Issue type
  [ ] Feature request <!-- An enhancement of existing functionality -->
  [X] Bug report      <!-- Unexpected or erroneous behavior -->
  [ ] Documentation   <!-- A modification to the documentation -->
  
  <!--
      Please describe the environment in which you are running NetBox. (Be sure
      to verify that you are running the latest stable release of NetBox before
      submitting a bug report.) If you are submitting a bug report and have made
      any changes to the code base, please first validate that your bug can be
      recreated while running an official release.
  -->
  ### Environment
  * Python version:  python 2.7.5
  * NetBox version:  develop-2.4
  
  <!--
      BUG REPORTS must include:
          * A list of the steps needed for someone else to reproduce the bug
          * A description of the expected and observed behavior
          * Any relevant error messages (screenshots may also help)
  
      FEATURE REQUESTS must include:
          * A detailed description of the proposed functionality
          * A use case for the new feature
          * A rough description of any necessary changes to the database schema
          * Any relevant third-party libraries which would be needed
  -->
  ### Description
  Testing out the webhook implementation and discovered the following bug:
       when a model contains a custom field of type date the worker is unable to serialize the data for transmission
  
  ```
  Traceback (most recent call last):
    File "/usr/lib/python2.7/site-packages/rq/worker.py", line 793, in perform_job
      rv = job.perform()
    File "/usr/lib/python2.7/site-packages/rq/job.py", line 599, in perform
      self._result = self._execute()
    File "/usr/lib/python2.7/site-packages/rq/job.py", line 605, in _execute
      return self.func(*self.args, **self.kwargs)
    File "/opt/netbox/netbox/extras/webhooks_worker.py", line 44, in process_webhook
      prepared_request = requests.Request(**params).prepare()
    File "/usr/lib/python2.7/site-packages/requests/models.py", line 259, in prepare
      hooks=self.hooks,
    File "/usr/lib/python2.7/site-packages/requests/models.py", line 307, in prepare
      self.prepare_body(data, files, json)
    File "/usr/lib/python2.7/site-packages/requests/models.py", line 427, in prepare_body
      body = json_dumps(json)
    File "/usr/lib64/python2.7/site-packages/simplejson/__init__.py", line 382, in dumps
      return _default_encoder.encode(obj)
    File "/usr/lib64/python2.7/site-packages/simplejson/encoder.py", line 291, in encode
      chunks = self.iterencode(o, _one_shot=True)
    File "/usr/lib64/python2.7/site-packages/simplejson/encoder.py", line 373, in iterencode
      return _iterencode(o, 0)
    File "/usr/lib64/python2.7/site-packages/simplejson/encoder.py", line 268, in default
      o.__class__.__name__)
  TypeError: Object of type date is not JSON serializable
  ```
  
  </issue>
  <code>
  [start of netbox/extras/webhooks_worker.py]
  1 import hashlib
  2 import hmac
  3 
  4 import requests
  5 from django_rq import job
  6 
  7 from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJECTCHANGE_ACTION_CHOICES
  8 
  9 
  10 @job('default')
  11 def process_webhook(webhook, data, model_class, event, timestamp):
  12     """
  13     Make a POST request to the defined Webhook
  14     """
  15     payload = {
  16         'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event],
  17         'timestamp': timestamp,
  18         'model': model_class.__name__,
  19         'data': data
  20     }
  21     headers = {
  22         'Content-Type': webhook.get_http_content_type_display(),
  23     }
  24     params = {
  25         'method': 'POST',
  26         'url': webhook.payload_url,
  27         'headers': headers
  28     }
  29 
  30     if webhook.http_content_type == WEBHOOK_CT_JSON:
  31         params.update({'json': payload})
  32     elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:
  33         params.update({'data': payload})
  34 
  35     prepared_request = requests.Request(**params).prepare()
  36 
  37     if webhook.secret != '':
  38         # sign the request with the secret
  39         hmac_prep = hmac.new(bytearray(webhook.secret, 'utf8'), prepared_request.body, digestmod=hashlib.sha512)
  40         prepared_request.headers['X-Hook-Signature'] = hmac_prep.hexdigest()
  41 
  42     with requests.Session() as session:
  43         session.verify = webhook.ssl_verification
  44         response = session.send(prepared_request)
  45 
  46     if response.status_code >= 200 and response.status_code <= 299:
  47         return 'Status {} returned, webhook successfully processed.'.format(response.status_code)
  48     else:
  49         raise requests.exceptions.RequestException(
  50             "Status {} returned, webhook FAILED to process.".format(response.status_code)
  51         )
  52
  [end of netbox/extras/webhooks_worker.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/netbox/extras/webhooks_worker.py b/netbox/extras/webhooks_worker.py
  --- a/netbox/extras/webhooks_worker.py
  +++ b/netbox/extras/webhooks_worker.py
  @@ -1,8 +1,10 @@
   import hashlib
   import hmac
  -
   import requests
  +import json
  +
   from django_rq import job
  +from rest_framework.utils.encoders import JSONEncoder
   
   from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJECTCHANGE_ACTION_CHOICES
   
  @@ -13,9 +15,9 @@
       Make a POST request to the defined Webhook
       """
       payload = {
  -        'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event],
  +        'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(),
           'timestamp': timestamp,
  -        'model': model_class.__name__,
  +        'model': model_class._meta.model_name,
           'data': data
       }
       headers = {
  @@ -28,7 +30,7 @@
       }
   
       if webhook.http_content_type == WEBHOOK_CT_JSON:
  -        params.update({'json': payload})
  +        params.update({'data': json.dumps(payload, cls=JSONEncoder)})
       elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:
           params.update({'data': payload})
  
verification_info: {"golden_diff": "diff --git a/netbox/extras/webhooks_worker.py b/netbox/extras/webhooks_worker.py\n--- a/netbox/extras/webhooks_worker.py\n+++ b/netbox/extras/webhooks_worker.py\n@@ -1,8 +1,10 @@\n import hashlib\n import hmac\n-\n import requests\n+import json\n+\n from django_rq import job\n+from rest_framework.utils.encoders import JSONEncoder\n \n from extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJECTCHANGE_ACTION_CHOICES\n \n@@ -13,9 +15,9 @@\n     Make a POST request to the defined Webhook\n     \"\"\"\n     payload = {\n-        'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event],\n+        'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event].lower(),\n         'timestamp': timestamp,\n-        'model': model_class.__name__,\n+        'model': model_class._meta.model_name,\n         'data': data\n     }\n     headers = {\n@@ -28,7 +30,7 @@\n     }\n \n     if webhook.http_content_type == WEBHOOK_CT_JSON:\n-        params.update({'json': payload})\n+        params.update({'data': json.dumps(payload, cls=JSONEncoder)})\n     elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:\n         params.update({'data': payload})\n", "issue": "deficiency in new webhook implementation\n<!--\r\n    Before opening a new issue, please search through the existing issues to\r\n    see if your topic has already been addressed. Note that you may need to\r\n    remove the \"is:open\" filter from the search bar to include closed issues.\r\n\r\n    Check the appropriate type for your issue below by placing an x between the\r\n    brackets. For assistance with installation issues, or for any other issues\r\n    other than those listed below, please raise your topic for discussion on\r\n    our mailing list:\r\n\r\n        https://groups.google.com/forum/#!forum/netbox-discuss\r\n\r\n    Please note that issues which do not fall under any of the below categories\r\n    will be closed. Due to an excessive backlog of feature requests, we are\r\n    not currently accepting any proposals which extend NetBox's feature scope.\r\n\r\n    Do not prepend any sort of tag to your issue's title. An administrator will\r\n    review your issue and assign labels as appropriate.\r\n--->\r\n### Issue type\r\n[ ] Feature request <!-- An enhancement of existing functionality -->\r\n[X] Bug report      <!-- Unexpected or erroneous behavior -->\r\n[ ] Documentation   <!-- A modification to the documentation -->\r\n\r\n<!--\r\n    Please describe the environment in which you are running NetBox. (Be sure\r\n    to verify that you are running the latest stable release of NetBox before\r\n    submitting a bug report.) If you are submitting a bug report and have made\r\n    any changes to the code base, please first validate that your bug can be\r\n    recreated while running an official release.\r\n-->\r\n### Environment\r\n* Python version:  python 2.7.5\r\n* NetBox version:  develop-2.4\r\n\r\n<!--\r\n    BUG REPORTS must include:\r\n        * A list of the steps needed for someone else to reproduce the bug\r\n        * A description of the expected and observed behavior\r\n        * Any relevant error messages (screenshots may also help)\r\n\r\n    FEATURE REQUESTS must include:\r\n        * A detailed description of the proposed functionality\r\n        * A use case for the new feature\r\n        * A rough description of any necessary changes to the database schema\r\n        * Any relevant third-party libraries which would be needed\r\n-->\r\n### Description\r\nTesting out the webhook implementation and discovered the following bug:\r\n     when a model contains a custom field of type date the worker is unable to serialize the data for transmission\r\n\r\n```\r\nTraceback (most recent call last):\r\n  File \"/usr/lib/python2.7/site-packages/rq/worker.py\", line 793, in perform_job\r\n    rv = job.perform()\r\n  File \"/usr/lib/python2.7/site-packages/rq/job.py\", line 599, in perform\r\n    self._result = self._execute()\r\n  File \"/usr/lib/python2.7/site-packages/rq/job.py\", line 605, in _execute\r\n    return self.func(*self.args, **self.kwargs)\r\n  File \"/opt/netbox/netbox/extras/webhooks_worker.py\", line 44, in process_webhook\r\n    prepared_request = requests.Request(**params).prepare()\r\n  File \"/usr/lib/python2.7/site-packages/requests/models.py\", line 259, in prepare\r\n    hooks=self.hooks,\r\n  File \"/usr/lib/python2.7/site-packages/requests/models.py\", line 307, in prepare\r\n    self.prepare_body(data, files, json)\r\n  File \"/usr/lib/python2.7/site-packages/requests/models.py\", line 427, in prepare_body\r\n    body = json_dumps(json)\r\n  File \"/usr/lib64/python2.7/site-packages/simplejson/__init__.py\", line 382, in dumps\r\n    return _default_encoder.encode(obj)\r\n  File \"/usr/lib64/python2.7/site-packages/simplejson/encoder.py\", line 291, in encode\r\n    chunks = self.iterencode(o, _one_shot=True)\r\n  File \"/usr/lib64/python2.7/site-packages/simplejson/encoder.py\", line 373, in iterencode\r\n    return _iterencode(o, 0)\r\n  File \"/usr/lib64/python2.7/site-packages/simplejson/encoder.py\", line 268, in default\r\n    o.__class__.__name__)\r\nTypeError: Object of type date is not JSON serializable\r\n```\n", "before_files": [{"content": "import hashlib\nimport hmac\n\nimport requests\nfrom django_rq import job\n\nfrom extras.constants import WEBHOOK_CT_JSON, WEBHOOK_CT_X_WWW_FORM_ENCODED, OBJECTCHANGE_ACTION_CHOICES\n\n\n@job('default')\ndef process_webhook(webhook, data, model_class, event, timestamp):\n    \"\"\"\n    Make a POST request to the defined Webhook\n    \"\"\"\n    payload = {\n        'event': dict(OBJECTCHANGE_ACTION_CHOICES)[event],\n        'timestamp': timestamp,\n        'model': model_class.__name__,\n        'data': data\n    }\n    headers = {\n        'Content-Type': webhook.get_http_content_type_display(),\n    }\n    params = {\n        'method': 'POST',\n        'url': webhook.payload_url,\n        'headers': headers\n    }\n\n    if webhook.http_content_type == WEBHOOK_CT_JSON:\n        params.update({'json': payload})\n    elif webhook.http_content_type == WEBHOOK_CT_X_WWW_FORM_ENCODED:\n        params.update({'data': payload})\n\n    prepared_request = requests.Request(**params).prepare()\n\n    if webhook.secret != '':\n        # sign the request with the secret\n        hmac_prep = hmac.new(bytearray(webhook.secret, 'utf8'), prepared_request.body, digestmod=hashlib.sha512)\n        prepared_request.headers['X-Hook-Signature'] = hmac_prep.hexdigest()\n\n    with requests.Session() as session:\n        session.verify = webhook.ssl_verification\n        response = session.send(prepared_request)\n\n    if response.status_code >= 200 and response.status_code <= 299:\n        return 'Status {} returned, webhook successfully processed.'.format(response.status_code)\n    else:\n        raise requests.exceptions.RequestException(\n            \"Status {} returned, webhook FAILED to process.\".format(response.status_code)\n        )\n", "path": "netbox/extras/webhooks_worker.py"}]}