#31973: TypeError loading data in JSONField if DB has native JSON support
-------------------------------------+-------------------------------------
     Reporter:  Adam Alton           |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  3.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  needsinfo
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  0                    |                    UI/UX:  0
-------------------------------------+-------------------------------------

Comment (by Adam Alton):

 Thanks for your swift reply, @felixxm. You're right, this is caused by the
 database having the fields as type `json` rather than `jsonb`, even though
 the DB schema has only ever been altered via Django's migrations.

 So (contrary to my original report) there is not a bug in `value_from_db`.

 The question now is whether there's a bug in Django's migration logic.

 The fields which were getting this error were originally using a custom
 `JSONField`, which was a subclass of `models.TextField`, and so presumably
 their original DB column type was `text`. I then changed them to use the
 native `models.JSONField`, and got Django to automatically create a
 migration (which contains a `migrations.AlterField` operation for each
 field, converting them to the native `models.JSONField`).

 The weird thing is that that migration converted the DB columns to type
 `json` rather than `jsonb`.

 I can fix that in my own DB, no problem. But the remaining question is
 this: is that behaviour unexpected and should we fix it?

 It seems unexpected to me that Django is happily creating the migration
 and applying it, but that the DB then ends up in an unusable state.
 Presumably Django should either say "I can't do that change, write your
 own migration" or it should apply the correct change.

 Happy to make a new ticket if the decision is that this is a valid bug.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/31973#comment:4>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/067.1ac442c45ddc83f8657aa1a009e9f7d1%40djangoproject.com.

Reply via email to