derek-schaefer/django-json-field — pull request #7 by mjtorn (2012-06-29 11:09:18+00:00)
Title: DecoderError on basestring

Hi!

Noticed my tests started failing and I found (with the help of _bisect_)
that "77da4d283236fd949906c8fb1367df03500c5baa is the first bad commit"

The behavior turned out that I couldn't assign like 'a', to a json field anymore;

```
/home/mjt/src/git_checkouts/django-json-field/json_field/fields.pyc in to_python(self, value)
89 return None
90 if isinstance(value, basestring):
---> 91 value = json.loads(value, **self.decoder_kwargs)
92 return value
93
[...]
JSONDecodeError: No JSON object could be decoded: line 1 column 0 (char 0)
```

Sure, JSON is identified as a basestring but this is not necessarily what we mean by it ;)

Not sure if this is a problem or not, as we'd usually assign 'a' to it, but if we assign '"a"'
we do **not** end up with 'a' as the value. Instead it gets parsed into _a_, apparently ends
up in _JSONDecoder.decode_ -> _isinstance(obj, basestring)_ and eventually _date_parser.parse(obj)_
which interprets it as a valid date.

Assigning 'ab' and '"ab"' work the same.

Assigning '1' makes it an integer but '"1"' a _Decimal_ for the above reasons.

If these findings should be considered problems they should probably be fixed separately.

This pull request is about a real-world problem anyway with assigning strings :)