Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make non-null fields required #36

Merged
merged 1 commit into from
Nov 25, 2018

Conversation

cdman
Copy link

@cdman cdman commented May 17, 2018

No description provided.

@cdman
Copy link
Author

cdman commented May 17, 2018

Hello everyone,

I'm not sure that this is the right solution, however I'm pretty sure that this is a "real" problem. To sum it up, I would expect the following code to raise an IntegrityError, just as it does if you replace PickledObjectField with an IntegerField for example (because it doesn't have null=True):

class MinimalTestingModel(models.Model):
    field = PickledObjectField()

MinimalTestingModel.objects.create()

Currently it silently stores an unicode empty string (u'') in such cases.

@coveralls
Copy link

coveralls commented May 17, 2018

Coverage Status

Coverage increased (+4.6%) to 96.629% when pulling 6313b66 on gpanther:warn-on-unset-value into dfa4f6e on gintas:master.

Copy link
Collaborator

@charettes charettes left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

While backward incompatible I feel like this is an issue that should be fixed.

@@ -105,8 +105,7 @@ def get_default(self):
if callable(self.default):
return self.default()
return self.default
# If the field doesn't have a default, then we punt to models.Field.
return super(PickledObjectField, self).get_default()
return None
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the appropriate solution might be to set PickledObjectField.empty_strings_allowed = False.

https://github.com/django/django/blob/63de263e030d2a3fd7ff62ae9bc809a5572d351a/django/db/models/fields/__init__.py#L807

@cdman cdman force-pushed the warn-on-unset-value branch 2 times, most recently from 1a10d4f to 0c6723c Compare May 18, 2018 12:25
@cdman
Copy link
Author

cdman commented May 18, 2018

@charettes - thanks for the quick reaction. I updated the code to use the proposed solution (the one with empty_strings_allowed = False).

All the best.

@charettes
Copy link
Collaborator

@cdman looking good! Do you think you could rebase on top of master and mention this change in the README.rst for the 1.1.0 version.

@cdman cdman force-pushed the warn-on-unset-value branch 2 times, most recently from 2d174aa to e8d52ee Compare May 21, 2018 16:21
@cdman
Copy link
Author

cdman commented May 21, 2018

@charettes - done. I'm a little un-easy about releasing such a breaking change in a minor version bump but it's your call 😄.

@charettes
Copy link
Collaborator

@cdman I rebased your branch for 2.0 which I plan to release today.

@charettes charettes force-pushed the warn-on-unset-value branch 2 times, most recently from 74ea3e6 to 6313b66 Compare November 25, 2018 13:47
That enforces the usage of `null=True` to store empty values.
@charettes charettes merged commit 46e229e into gintas:master Nov 25, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants