1
0
mirror of https://github.com/django/django.git synced 2025-10-28 08:06:09 +00:00

[1.11.x] Fixed #28188 -- Fixed crash when pickling model fields.

Regression in d2a26c1a90.

Thanks Adam Alton for the report and test, and Adam Johnson for
suggesting the fix.

Backport of a9874d48b1 from master
This commit is contained in:
Tim Graham
2017-05-11 21:04:52 -04:00
parent 643413f654
commit 74b0837bef
3 changed files with 16 additions and 1 deletions

View File

@@ -1,3 +1,5 @@
import pickle
from django import forms
from django.db import models
from django.test import SimpleTestCase, TestCase
@@ -76,6 +78,13 @@ class BasicFieldTests(TestCase):
self.assertIsNotNone(f1)
self.assertNotIn(f2, (None, 1, ''))
def test_field_instance_is_picklable(self):
"""Field instances can be pickled."""
field = models.Field(max_length=100, default='a string')
# Must be picklable with this cached property populated (#28188).
field._get_default
pickle.dumps(field)
class ChoicesTests(SimpleTestCase):