Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#25393 closed Bug (fixed)

Cannot add TextField with unhashable default with MySQL

Reported by: Ville Skyttä Owned by: nobody
Component: Database layer (models, ORM) Version: master
Severity: Normal Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

Adding a TextField that has an unhashable default fails with MySQL, for example with {} as the default:

Traceback (most recent call last):
[...]
  File "[...]/django/db/backends/mysql/schema.py", line 53, in add_field
    if self.skip_default(field) and field.default not in {None, NOT_PROVIDED}:
TypeError: unhashable type: 'dict'

One use case for fields like this is JSONField at https://github.com/bradjasper/django-jsonfield

Change History (14)

comment:1 Changed 4 years ago by Ville Skyttä

Has patch: set

comment:2 Changed 4 years ago by Tim Graham

Triage Stage: UnreviewedAccepted

comment:3 Changed 4 years ago by Markus Holtermann

Needs documentation: set

comment:4 Changed 4 years ago by Ville Skyttä

Needs documentation: unset

PR force-updated with commit containing requested docs.

comment:5 Changed 4 years ago by Anton Baklanov

Patch needs improvement: set

Trivial spelling fix required, see PR.

comment:6 Changed 4 years ago by Ville Skyttä

Patch needs improvement: unset

PR updated

comment:7 Changed 4 years ago by Anton Baklanov

Triage Stage: AcceptedReady for checkin

Looks good.

comment:8 Changed 4 years ago by Anton Baklanov

Triage Stage: Ready for checkinAccepted

comment:9 Changed 4 years ago by Anton Baklanov

Patch needs improvement: set

comment:10 Changed 4 years ago by Anton Baklanov

Looks like there is some room for minor test improvement, left two comments on PR.
Thanks.

comment:11 Changed 4 years ago by Ville Skyttä

Patch needs improvement: unset

PR updated

comment:12 Changed 4 years ago by Anton Baklanov

Triage Stage: AcceptedReady for checkin

Thanks!

comment:13 Changed 4 years ago by Tim Graham <timograham@…>

Resolution: fixed
Status: newclosed

In 4d933ad:

Fixed #25393 -- Fixed MySQL crash when adding text/blob field with unhashable default.

comment:14 Changed 4 years ago by Tim Graham <timograham@…>

In 69017bad:

[1.8.x] Fixed #25393 -- Fixed MySQL crash when adding text/blob field with unhashable default.

Backport of 4d933ad4181a511f3ced98edba4e17aff054e0e2 from master

Note: See TracTickets for help on using tickets.
Back to Top