-
Notifications
You must be signed in to change notification settings - Fork 142
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
handle none #92
handle none #92
Conversation
What bug are you trying to solve? I'm not aware of a bug that has to do with None values, so if there is any, how can I reproduce it? |
I am getting "'NoneType' object does not support item assignment" in a few places. When trying to save for example on a model with hstore field. I have allowed null on it. data = hstore.DictionaryField(
schema=[
{
"name": "wikipedia",
"class": "URLField",
"kwargs": {"blank": True}
},
{
"name": "homepage",
"class": "URLField",
"kwargs": {"blank": True}
},
]
) The migration I posted in description shows that null is allowed. When I edit in admin, set in django-hstore/django_hstore/virtual.py is getting called. def __set__(self, instance, value):
"""
set value on hstore dictionary
"""
hstore_dictionary = getattr(instance, self.hstore_field_name)
hstore_dictionary[self.name] = value As you can see there is no None handling. I handled None in one place, am going to handle it here too. Let me know if I am doing something wrong to have all these nulls in DB to begin with. Else we should handle nulls like I am doing. |
@nemesisdesign any thoughts? |
I think this patch needs a test to replicate the bug in the automated test environment and then apply the patch. |
on which version of django bytheway? |
I am using django 1.7. I will try to create a patch containing tests. |
|
I'm seeing the same issue -- I swapped from blank=True to null=True,blank=True to solve another error, and then this error started appearing on fields without data in them. |
I tried altering class SchemaDataBag(HStoreModel):
name = models.CharField(max_length=32)
data = hstore.DictionaryField(null=True, blank=True, schema=[
{
'name': 'number',
'class': 'IntegerField',
'kwargs': {
'default': 0
}
}
# ... [cut] ...
]) Then ran the tests, all passed. How can I reproduce the issue you are experiencing? Even if you don't have time to write a test case, just write here the general steps. Let me know. Federico |
I ran into this issue, and found a way to reproduce it. I just created a new blank django project to test this issue. Here is my requirements:
Then I created a stupid model: class Document(models.Model):
title = models.CharField(max_length=255)
data = hstore.DictionaryField(null=True, blank=True, schema=[
{
'name': 'number',
'class': 'IntegerField',
'kwargs': {
'default': 0
}
},
{
'name': 'float',
'class': 'FloatField',
'kwargs': {
'default': 1.0
}
}
]) In a shell, I do this: >>> from documents.models import Document
>>> doc = Document()
>>> doc.title = 'test'
>>> doc.data = None
>>> doc.save() Now, if I try to visualize this document in the admin module, I've got this exception:
I met the issue in my real project because the "data" field was added through a migration, and the values were defaulted to "None". Applying the patch in this pull request fixes the issue. Hope that helps. |
test case here: 2c7d49d |
\o/ :-) |
My migrations contains:
Not sure if this is the proper fix, or if I should create the field non null with default value of empty dictionaty.
I think I followed the instructions.