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

Behaviour when null=True really sucks #69

Closed
nemesifier opened this issue Sep 23, 2014 · 1 comment
Closed

Behaviour when null=True really sucks #69

nemesifier opened this issue Sep 23, 2014 · 1 comment
Labels

Comments

@nemesifier
Copy link
Member

When the null attribute is set to True in a DictionaryField, the behaviour sucks.

Because the default value of the dictionary becomes None, trying to setting or getting keys from the dictionary returns a TypeError exception:

set example:

n.data['test'] = 'test'

get example:

n.data.get('test', 'default value')

These two lines both generate an exception.

To mitigate this, one would always have to do something like:

n.data = n.data or {}
n.data['test'] = 'test'

or:

try:
    n.data['test'] = 'test'
except TypeError:
    n.data = {}
    n.data['test'] = 'test'

which generates a lot of redundant, useless, ugly code which also slows down development.

One solution could be to not use null=True at all, but at the present moment the only way i could find to add an hstore field to an existing database table is setting the default value to NULL, which makes possible to add the field in the table but renders development clunky.

I propose that the fallback value of an HStoreField must always be an empty HStoreDict, even when null values are allowed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant