Comments (11)
I found a workaround. Doing a json.dumps
gets rid of the issue.
My dict was like:
mydic = { "key": "value"}
I stored it as valid json by:
class NotificationTemplate(models.Model):
extra = JSONField(default=json.dumps(NOTIFICATION_TEMPLATE_EXTRA)))
Remove the json.dumps
it gets stored as:
{ 'key': 'value'}
which is invalid
from django-annoying.
Hmm, I wonder why get_default
behaves like that. It's odd to me, because I've been setting the default to an empty dict ({}
) for ages and it works fine, although this code would make it seem like it shouldn't work...
from django-annoying.
What django version are you on? I am working on 1.6.
from django-annoying.
I've been through 1.5 to 1.7, and it's always worked. All my fields have always been JSONField(default={})
.
from django-annoying.
That's really odd. Maybe your fields inherit from something more than just JSONField
, with custom get_default
?
from django-annoying.
No, they're vanilla JSONFields... Are you seeing the problem when you save objects in the admin, perhaps?
from django-annoying.
Nope, but I think I have this problem mostly when I am using SQLite (in test environment). I will try to reproduce this and let you know.
from django-annoying.
A valid JSON would be something like {"key": "value"}
But if we store a static dict as the default, it gets stored as {'key': 'value'} which becomes an Invalid JSON.
Any workaround for this?
from django-annoying.
Hmm, this definitely shouldn't be the case. Can you post a small sample that reproduces the problem?
from django-annoying.
That's very odd. I'll try to have a look and see why this happens, thanks.
from django-annoying.
Fixed in 6912356, as @nebril suggested. Thank you all for the report!
from django-annoying.
Related Issues (20)
- Django 3.2 compatibility? HOT 1
- Django5 Support? HOT 1
- Possible to add support for types? HOT 2
- Can we get Pypi updated with the thread safe changes? HOT 1
- Test don't run against Django 1.7+ HOT 2
- Django 1.9 HOT 6
- Django 1.9: Cannot import name SingleRelatedObjectDescriptor HOT 4
- JSONField is not working in Django 1.9+
- AutoOneToOne doesn't work HOT 14
- Remove pretty-print from the JSON field output or make it configurable HOT 2
- Django 1.11 middleware HOT 3
- Please add a release with a universal wheel to PyPI HOT 1
- Could you publish a new release? HOT 4
- AutoOneToOneField breaks Django admin lookups HOT 5
- Using AutoOneToOneField with proxy model HOT 2
- Race Condition Fix HOT 3
- Setting HTTP status code when using ajax_request HOT 3
- ImportError: cannot import name 'six' HOT 2
- I know this is ancient history but a breaking change in a point release? HOT 6
- Support for django v3 HOT 3
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from django-annoying.