We are currently solving the following issue within our repository. Here is the issue text:
--- BEGIN ISSUE ---
django_polymorphic breaks model generation
`django_polymorphic` adds mandatory fields (named `*_ptr`) to models, but gives them values when the model is created. Hypothesis sees these as normal non-nullable fields, which trigger the relevant health check. However, explicitly providing a value for one of these fields causes an exception to be thrown in the model's constructor.


--- END ISSUE ---

Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
--- BEGIN FILES ---
Path: `src/hypothesis/extra/django/models.py`
Content:
```
1 # coding=utf-8
2 #
3 # This file is part of Hypothesis (https://github.com/DRMacIver/hypothesis)
4 #
5 # Most of this work is copyright (C) 2013-2015 David R. MacIver
6 # (david@drmaciver.com), but it contains contributions by others. See
7 # https://github.com/DRMacIver/hypothesis/blob/master/CONTRIBUTING.rst for a
8 # full list of people who may hold copyright, and consult the git log if you
9 # need to determine who owns an individual contribution.
10 #
11 # This Source Code Form is subject to the terms of the Mozilla Public License,
12 # v. 2.0. If a copy of the MPL was not distributed with this file, You can
13 # obtain one at http://mozilla.org/MPL/2.0/.
14 #
15 # END HEADER
16 
17 from __future__ import division, print_function, absolute_import
18 
19 import django.db.models as dm
20 from django.db import IntegrityError
21 
22 import hypothesis.strategies as st
23 import hypothesis.extra.fakefactory as ff
24 from hypothesis.errors import InvalidArgument
25 from hypothesis.extra.datetime import datetimes
26 from hypothesis.searchstrategy.strategies import SearchStrategy
27 
28 
29 class ModelNotSupported(Exception):
30     pass
31 
32 
33 def referenced_models(model, seen=None):
34     if seen is None:
35         seen = set()
36     for f in model._meta.concrete_fields:
37         if isinstance(f, dm.ForeignKey):
38             t = f.rel.to
39             if t not in seen:
40                 seen.add(t)
41                 referenced_models(t, seen)
42     return seen
43 
44 
45 __default_field_mappings = None
46 
47 
48 def field_mappings():
49     global __default_field_mappings
50 
51     if __default_field_mappings is None:
52         __default_field_mappings = {
53             dm.SmallIntegerField: st.integers(-32768, 32767),
54             dm.IntegerField: st.integers(-2147483648, 2147483647),
55             dm.BigIntegerField:
56                 st.integers(-9223372036854775808, 9223372036854775807),
57             dm.PositiveIntegerField: st.integers(0, 2147483647),
58             dm.PositiveSmallIntegerField: st.integers(0, 32767),
59             dm.BinaryField: st.binary(),
60             dm.BooleanField: st.booleans(),
61             dm.CharField: st.text(),
62             dm.TextField: st.text(),
63             dm.DateTimeField: datetimes(allow_naive=False),
64             dm.EmailField: ff.fake_factory(u'email'),
65             dm.FloatField: st.floats(),
66             dm.NullBooleanField: st.one_of(st.none(), st.booleans()),
67         }
68     return __default_field_mappings
69 
70 
71 def add_default_field_mapping(field_type, strategy):
72     field_mappings()[field_type] = strategy
73 
74 
75 def models(model, **extra):
76     result = {}
77     mappings = field_mappings()
78     mandatory = set()
79     for f in model._meta.concrete_fields:
80         if isinstance(f, dm.AutoField):
81             continue
82         try:
83             mapped = mappings[type(f)]
84         except KeyError:
85             if not f.null:
86                 mandatory.add(f.name)
87             continue
88         if f.null:
89             mapped = st.one_of(st.none(), mapped)
90         result[f.name] = mapped
91     missed = {x for x in mandatory if x not in extra}
92     if missed:
93         raise InvalidArgument((
94             u'Missing arguments for mandatory field%s %s for model %s' % (
95                 u's' if len(missed) > 1 else u'',
96                 u', '.join(missed),
97                 model.__name__,
98             )))
99     for k, v in extra.items():
100         if isinstance(v, SearchStrategy):
101             result[k] = v
102         else:
103             result[k] = st.just(v)
104     result.update(extra)
105     return ModelStrategy(model, result)
106 
107 
108 class ModelStrategy(SearchStrategy):
109 
110     def __init__(self, model, mappings):
111         super(ModelStrategy, self).__init__()
112         self.model = model
113         self.arg_strategy = st.fixed_dictionaries(mappings)
114 
115     def __repr__(self):
116         return u'ModelStrategy(%s)' % (self.model.__name__,)
117 
118     def do_draw(self, data):
119         try:
120             result, _ = self.model.objects.get_or_create(
121                 **self.arg_strategy.do_draw(data)
122             )
123             return result
124         except IntegrityError:
125             data.mark_invalid()
126
```
--- 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()

```

diff --git a/src/hypothesis/extra/django/models.py b/src/hypothesis/extra/django/models.py
--- a/src/hypothesis/extra/django/models.py
+++ b/src/hypothesis/extra/django/models.py
@@ -23,6 +23,7 @@
 import hypothesis.extra.fakefactory as ff
 from hypothesis.errors import InvalidArgument
 from hypothesis.extra.datetime import datetimes
+from hypothesis.utils.conventions import UniqueIdentifier
 from hypothesis.searchstrategy.strategies import SearchStrategy
 
 
@@ -72,6 +73,9 @@
     field_mappings()[field_type] = strategy
 
 
+default_value = UniqueIdentifier(u'default_value')
+
+
 def models(model, **extra):
     result = {}
     mappings = field_mappings()
@@ -96,12 +100,9 @@
                 u', '.join(missed),
                 model.__name__,
             )))
-    for k, v in extra.items():
-        if isinstance(v, SearchStrategy):
-            result[k] = v
-        else:
-            result[k] = st.just(v)
     result.update(extra)
+    # Remove default_values so we don't try to generate anything for those.
+    result = {k: v for k, v in result.items() if v is not default_value}
     return ModelStrategy(model, result)

{"golden_diff": "diff --git a/src/hypothesis/extra/django/models.py b/src/hypothesis/extra/django/models.py\n--- a/src/hypothesis/extra/django/models.py\n+++ b/src/hypothesis/extra/django/models.py\n@@ -23,6 +23,7 @@\n import hypothesis.extra.fakefactory as ff\n from hypothesis.errors import InvalidArgument\n from hypothesis.extra.datetime import datetimes\n+from hypothesis.utils.conventions import UniqueIdentifier\n from hypothesis.searchstrategy.strategies import SearchStrategy\n \n \n@@ -72,6 +73,9 @@\n     field_mappings()[field_type] = strategy\n \n \n+default_value = UniqueIdentifier(u'default_value')\n+\n+\n def models(model, **extra):\n     result = {}\n     mappings = field_mappings()\n@@ -96,12 +100,9 @@\n                 u', '.join(missed),\n                 model.__name__,\n             )))\n-    for k, v in extra.items():\n-        if isinstance(v, SearchStrategy):\n-            result[k] = v\n-        else:\n-            result[k] = st.just(v)\n     result.update(extra)\n+    # Remove default_values so we don't try to generate anything for those.\n+    result = {k: v for k, v in result.items() if v is not default_value}\n     return ModelStrategy(model, result)\n", "issue": "django_polymorphic breaks model generation\n`django_polymorphic` adds mandatory fields (named `*_ptr`) to models, but gives them values when the model is created. Hypothesis sees these as normal non-nullable fields, which trigger the relevant health check. However, explicitly providing a value for one of these fields causes an exception to be thrown in the model's constructor.\n\n", "before_files": [{"content": "# coding=utf-8\n#\n# This file is part of Hypothesis (https://github.com/DRMacIver/hypothesis)\n#\n# Most of this work is copyright (C) 2013-2015 David R. MacIver\n# (david@drmaciver.com), but it contains contributions by others. See\n# https://github.com/DRMacIver/hypothesis/blob/master/CONTRIBUTING.rst for a\n# full list of people who may hold copyright, and consult the git log if you\n# need to determine who owns an individual contribution.\n#\n# This Source Code Form is subject to the terms of the Mozilla Public License,\n# v. 2.0. If a copy of the MPL was not distributed with this file, You can\n# obtain one at http://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom __future__ import division, print_function, absolute_import\n\nimport django.db.models as dm\nfrom django.db import IntegrityError\n\nimport hypothesis.strategies as st\nimport hypothesis.extra.fakefactory as ff\nfrom hypothesis.errors import InvalidArgument\nfrom hypothesis.extra.datetime import datetimes\nfrom hypothesis.searchstrategy.strategies import SearchStrategy\n\n\nclass ModelNotSupported(Exception):\n    pass\n\n\ndef referenced_models(model, seen=None):\n    if seen is None:\n        seen = set()\n    for f in model._meta.concrete_fields:\n        if isinstance(f, dm.ForeignKey):\n            t = f.rel.to\n            if t not in seen:\n                seen.add(t)\n                referenced_models(t, seen)\n    return seen\n\n\n__default_field_mappings = None\n\n\ndef field_mappings():\n    global __default_field_mappings\n\n    if __default_field_mappings is None:\n        __default_field_mappings = {\n            dm.SmallIntegerField: st.integers(-32768, 32767),\n            dm.IntegerField: st.integers(-2147483648, 2147483647),\n            dm.BigIntegerField:\n                st.integers(-9223372036854775808, 9223372036854775807),\n            dm.PositiveIntegerField: st.integers(0, 2147483647),\n            dm.PositiveSmallIntegerField: st.integers(0, 32767),\n            dm.BinaryField: st.binary(),\n            dm.BooleanField: st.booleans(),\n            dm.CharField: st.text(),\n            dm.TextField: st.text(),\n            dm.DateTimeField: datetimes(allow_naive=False),\n            dm.EmailField: ff.fake_factory(u'email'),\n            dm.FloatField: st.floats(),\n            dm.NullBooleanField: st.one_of(st.none(), st.booleans()),\n        }\n    return __default_field_mappings\n\n\ndef add_default_field_mapping(field_type, strategy):\n    field_mappings()[field_type] = strategy\n\n\ndef models(model, **extra):\n    result = {}\n    mappings = field_mappings()\n    mandatory = set()\n    for f in model._meta.concrete_fields:\n        if isinstance(f, dm.AutoField):\n            continue\n        try:\n            mapped = mappings[type(f)]\n        except KeyError:\n            if not f.null:\n                mandatory.add(f.name)\n            continue\n        if f.null:\n            mapped = st.one_of(st.none(), mapped)\n        result[f.name] = mapped\n    missed = {x for x in mandatory if x not in extra}\n    if missed:\n        raise InvalidArgument((\n            u'Missing arguments for mandatory field%s %s for model %s' % (\n                u's' if len(missed) > 1 else u'',\n                u', '.join(missed),\n                model.__name__,\n            )))\n    for k, v in extra.items():\n        if isinstance(v, SearchStrategy):\n            result[k] = v\n        else:\n            result[k] = st.just(v)\n    result.update(extra)\n    return ModelStrategy(model, result)\n\n\nclass ModelStrategy(SearchStrategy):\n\n    def __init__(self, model, mappings):\n        super(ModelStrategy, self).__init__()\n        self.model = model\n        self.arg_strategy = st.fixed_dictionaries(mappings)\n\n    def __repr__(self):\n        return u'ModelStrategy(%s)' % (self.model.__name__,)\n\n    def do_draw(self, data):\n        try:\n            result, _ = self.model.objects.get_or_create(\n                **self.arg_strategy.do_draw(data)\n            )\n            return result\n        except IntegrityError:\n            data.mark_invalid()\n", "path": "src/hypothesis/extra/django/models.py"}], "after_files": [{"content": "# coding=utf-8\n#\n# This file is part of Hypothesis (https://github.com/DRMacIver/hypothesis)\n#\n# Most of this work is copyright (C) 2013-2015 David R. MacIver\n# (david@drmaciver.com), but it contains contributions by others. See\n# https://github.com/DRMacIver/hypothesis/blob/master/CONTRIBUTING.rst for a\n# full list of people who may hold copyright, and consult the git log if you\n# need to determine who owns an individual contribution.\n#\n# This Source Code Form is subject to the terms of the Mozilla Public License,\n# v. 2.0. If a copy of the MPL was not distributed with this file, You can\n# obtain one at http://mozilla.org/MPL/2.0/.\n#\n# END HEADER\n\nfrom __future__ import division, print_function, absolute_import\n\nimport django.db.models as dm\nfrom django.db import IntegrityError\n\nimport hypothesis.strategies as st\nimport hypothesis.extra.fakefactory as ff\nfrom hypothesis.errors import InvalidArgument\nfrom hypothesis.extra.datetime import datetimes\nfrom hypothesis.utils.conventions import UniqueIdentifier\nfrom hypothesis.searchstrategy.strategies import SearchStrategy\n\n\nclass ModelNotSupported(Exception):\n    pass\n\n\ndef referenced_models(model, seen=None):\n    if seen is None:\n        seen = set()\n    for f in model._meta.concrete_fields:\n        if isinstance(f, dm.ForeignKey):\n            t = f.rel.to\n            if t not in seen:\n                seen.add(t)\n                referenced_models(t, seen)\n    return seen\n\n\n__default_field_mappings = None\n\n\ndef field_mappings():\n    global __default_field_mappings\n\n    if __default_field_mappings is None:\n        __default_field_mappings = {\n            dm.SmallIntegerField: st.integers(-32768, 32767),\n            dm.IntegerField: st.integers(-2147483648, 2147483647),\n            dm.BigIntegerField:\n                st.integers(-9223372036854775808, 9223372036854775807),\n            dm.PositiveIntegerField: st.integers(0, 2147483647),\n            dm.PositiveSmallIntegerField: st.integers(0, 32767),\n            dm.BinaryField: st.binary(),\n            dm.BooleanField: st.booleans(),\n            dm.CharField: st.text(),\n            dm.TextField: st.text(),\n            dm.DateTimeField: datetimes(allow_naive=False),\n            dm.EmailField: ff.fake_factory(u'email'),\n            dm.FloatField: st.floats(),\n            dm.NullBooleanField: st.one_of(st.none(), st.booleans()),\n        }\n    return __default_field_mappings\n\n\ndef add_default_field_mapping(field_type, strategy):\n    field_mappings()[field_type] = strategy\n\n\ndefault_value = UniqueIdentifier(u'default_value')\n\n\ndef models(model, **extra):\n    result = {}\n    mappings = field_mappings()\n    mandatory = set()\n    for f in model._meta.concrete_fields:\n        if isinstance(f, dm.AutoField):\n            continue\n        try:\n            mapped = mappings[type(f)]\n        except KeyError:\n            if not f.null:\n                mandatory.add(f.name)\n            continue\n        if f.null:\n            mapped = st.one_of(st.none(), mapped)\n        result[f.name] = mapped\n    missed = {x for x in mandatory if x not in extra}\n    if missed:\n        raise InvalidArgument((\n            u'Missing arguments for mandatory field%s %s for model %s' % (\n                u's' if len(missed) > 1 else u'',\n                u', '.join(missed),\n                model.__name__,\n            )))\n    result.update(extra)\n    # Remove default_values so we don't try to generate anything for those.\n    result = {k: v for k, v in result.items() if v is not default_value}\n    return ModelStrategy(model, result)\n\n\nclass ModelStrategy(SearchStrategy):\n\n    def __init__(self, model, mappings):\n        super(ModelStrategy, self).__init__()\n        self.model = model\n        self.arg_strategy = st.fixed_dictionaries(mappings)\n\n    def __repr__(self):\n        return u'ModelStrategy(%s)' % (self.model.__name__,)\n\n    def do_draw(self, data):\n        try:\n            result, _ = self.model.objects.get_or_create(\n                **self.arg_strategy.do_draw(data)\n            )\n            return result\n        except IntegrityError:\n            data.mark_invalid()\n", "path": "src/hypothesis/extra/django/models.py"}]}