[Django] #32435: Bug in JsonField creation with null=False

21 views
Skip to first unread message

Django

unread,
Feb 10, 2021, 4:43:52 AM2/10/21
to django-...@googlegroups.com
#32435: Bug in JsonField creation with null=False
-----------------------------------------+---------------------------
Reporter: rcampos87 | Owner: nobody
Type: Bug | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Keywords: jsonfield
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
-----------------------------------------+---------------------------
I recently updated my project's Django to version 3.1.5 and removed its
jsonfield dependency to use the new JSONField released with Django 3.1.
However i'm experiencing quite a strange bug.

I was experimenting creating a new JSONField with different options and
here is what i found:

Suppose I have a migration like this


{{{

migrations.AlterField(
model_name='awsuserschedule',
name='selected_ids',
field=common.fields.JSONField(encoder=common.encoders.JSONEncoder,
null=True),
),
migrations.AlterField(
model_name='awsuserschedule',
name='tags',
field=common.fields.JSONField(default=list,
encoder=common.encoders.JSONEncoder),
),
migrations.AlterField(
model_name='userscheduleslog',
name='instance_ids',
field=common.fields.JSONField(default=list,
encoder=common.encoders.JSONEncoder, null=False),
),
}}}

When i run sqlmigrate to analyze this migration i get:

{{{
-- Alter field selected_ids on awsuserschedule
--
ALTER TABLE `aws_user_schedules` MODIFY `selected_ids` json NULL;
--
-- Alter field tags on awsuserschedule
--
--
-- Alter field instance_ids on userscheduleslog
--
}}}

So you see that when '''null is not passed''', or '''null=False''', there
is no sql query created at all. I'm using MySQL 5.7.22. Am i doing
something wrong?

Thanks

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

Django

unread,
Feb 10, 2021, 4:44:54 AM2/10/21
to django-...@googlegroups.com
#32435: Bug in JsonField with null=False
--------------------------------+--------------------------------------
Reporter: Ronaldo Campos | Owner: nobody

Type: Bug | Status: new
Component: Uncategorized | Version: 3.1
Severity: Normal | Resolution:

Keywords: jsonfield | Triage Stage: Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------------+--------------------------------------
Changes (by Ronaldo Campos):

* cc: Ronaldo Campos (added)


--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:1>

Django

unread,
Feb 10, 2021, 4:55:38 AM2/10/21
to django-...@googlegroups.com
#32435: Bug in JsonField with null=False
-------------------------------------+-------------------------------------
Reporter: rcampos87 | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: needsinfo

Keywords: jsonfield | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* status: new => closed
* resolution: => needsinfo
* component: Uncategorized => Database layer (models, ORM)


Comment:

Thanks for this report, however there is not enough details to understand
or reproduce your issue. What kind of `JSONField` did you use before? What
was the models' state before this operations? Can you provide a sample
project?

--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:2>

Django

unread,
Feb 10, 2021, 9:16:45 AM2/10/21
to django-...@googlegroups.com
#32435: Bug in JsonField with null=False
-------------------------------------+-------------------------------------
Reporter: Ronaldo Campos | Owner: nobody

Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: needsinfo
Keywords: jsonfield | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

Comment (by Ronaldo Campos):

I was using the jsonfield library. But, never mind i think i figured out
what i was doing wrong. It was an issue on the previous migration states
that was causing sqlmigrate to avoid doing anything. Feel free to close
the bug report.

--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:3>

Django

unread,
Feb 10, 2021, 9:22:51 AM2/10/21
to django-...@googlegroups.com
#32435: Bug in JsonField with null=False
-------------------------------------+-------------------------------------
Reporter: Ronaldo Campos | Owner: nobody
Type: Bug | Status: closed
Component: Database layer | Version: 3.1
(models, ORM) |
Severity: Normal | Resolution: invalid

Keywords: jsonfield | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Mariusz Felisiak):

* resolution: needsinfo => invalid


Comment:

Thanks for the feedback.

--
Ticket URL: <https://code.djangoproject.com/ticket/32435#comment:4>

Reply all
Reply to author
Forward
0 new messages