diff --git a/README.rst b/README.rst index ef3329a..1f24c77 100644 --- a/README.rst +++ b/README.rst @@ -168,6 +168,10 @@ Changes in version 2.0.0 * Silenced ``RemovedInDjango30Warning`` warnings on Django 2.0+ (thanks to canarduck). * Restructured project directories. +* Disallowed the usage of empty strings for ``PickledObjectField``. That makes + ``.save()``, ``.create()``, etc. raise ``IntegrityError`` if `null` is not + ``True`` and no default value was specified like built-in fields do + (thanks to Attila-Mihaly Balazs). Changes in version 1.1.0 ======================== diff --git a/picklefield/fields.py b/picklefield/fields.py index 80c364a..745df70 100644 --- a/picklefield/fields.py +++ b/picklefield/fields.py @@ -87,6 +87,7 @@ class PickledObjectField(models.Field): can still do lookups using None). This way, it is still possible to use the ``isnull`` lookup type correctly. """ + empty_strings_allowed = False def __init__(self, *args, **kwargs): self.compress = kwargs.pop('compress', False) diff --git a/tests/tests.py b/tests/tests.py index 84f5bdb..7033213 100644 --- a/tests/tests.py +++ b/tests/tests.py @@ -1,6 +1,7 @@ import json from datetime import date +from django.db import IntegrityError from django.core import serializers from django.test import TestCase from picklefield.fields import dbsafe_encode, wrap_conflictual_object @@ -37,7 +38,7 @@ def test_data_integrity(self): # Make sure the default value for default_pickled_field gets stored # correctly and that it isn't converted to a string. - model_test = TestingModel() + model_test = TestingModel(pickle_field=1, compressed_pickle_field=1) model_test.save() model_test = TestingModel.objects.get(id__exact=model_test.id) self.assertEqual((D1, S1, T1, L1), model_test.default_pickle_field) @@ -172,3 +173,7 @@ def test_no_copy(self): compressed_pickle_field='Copy Me', non_copying_field='Dont copy me' ) + + def test_empty_strings_not_allowed(self): + with self.assertRaises(IntegrityError): + MinimalTestingModel.objects.create()