Giter Site home page Giter Site logo

Comments (11)

ketanbhatt avatar ketanbhatt commented on July 22, 2024 1

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.

skorokithakis avatar skorokithakis commented on July 22, 2024

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.

nebril avatar nebril commented on July 22, 2024

What django version are you on? I am working on 1.6.

from django-annoying.

skorokithakis avatar skorokithakis commented on July 22, 2024

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.

nebril avatar nebril commented on July 22, 2024

That's really odd. Maybe your fields inherit from something more than just JSONField, with custom get_default?

from django-annoying.

skorokithakis avatar skorokithakis commented on July 22, 2024

No, they're vanilla JSONFields... Are you seeing the problem when you save objects in the admin, perhaps?

from django-annoying.

nebril avatar nebril commented on July 22, 2024

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.

ketanbhatt avatar ketanbhatt commented on July 22, 2024

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.

skorokithakis avatar skorokithakis commented on July 22, 2024

Hmm, this definitely shouldn't be the case. Can you post a small sample that reproduces the problem?

from django-annoying.

skorokithakis avatar skorokithakis commented on July 22, 2024

That's very odd. I'll try to have a look and see why this happens, thanks.

from django-annoying.

skorokithakis avatar skorokithakis commented on July 22, 2024

Fixed in 6912356, as @nebril suggested. Thank you all for the report!

from django-annoying.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.