[Django] #31399: SchemaEditor._alter_field() looks for foreign key constraints even if the database doesn't support them

9 views
Skip to first unread message

Django

unread,
Mar 24, 2020, 8:06:09 PM3/24/20
to django-...@googlegroups.com
#31399: SchemaEditor._alter_field() looks for foreign key constraints even if the
database doesn't support them
--------------------------------------+------------------------
Reporter: Tim Graham | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------+------------------------
`BaseDatabaseSchemaEditor._alter_field()`
[https://github.com/django/django/blob/895f28f9cbed817c00ab68770433170d83132d90/django/db/backends/base/schema.py#L572-L582
does a lookup for foreign key constraints] even if the database doesn't
support them, resulting in test failures like this:
{{{
======================================================================
ERROR: test_alter_field_fk_keeps_index (schema.tests.SchemaTests)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/home/tim/code/django/tests/schema/tests.py", line 990, in
test_alter_field_fk_keeps_index
editor.alter_field(Book, old_field, new_field, strict=True)
File "/home/tim/code/django/django/db/backends/base/schema.py", line
535, in alter_field
old_db_params, new_db_params, strict)
File "/home/tim/code/django/django/db/backends/base/schema.py", line
548, in _alter_field
old_field.column,
ValueError: Found wrong number (0) of foreign key constraints for
schema_book.author_id
}}}
This is a problem only when the argument `strict=True` is used (which I
believe is only in tests).

To fix this, `self.connection.features.supports_foreign_keys` should be
consulted.

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

Django

unread,
Mar 25, 2020, 1:02:30 AM3/25/20
to django-...@googlegroups.com
#31399: SchemaEditor._alter_field() looks for foreign key constraints even if the
database doesn't support them.
----------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted

Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------+------------------------------------
Changes (by felixxm):

* easy: 0 => 1
* stage: Unreviewed => Accepted


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

Django

unread,
Mar 25, 2020, 9:20:28 AM3/25/20
to django-...@googlegroups.com
#31399: SchemaEditor._alter_field() looks for foreign key constraints even if the
database doesn't support them.
----------------------------+------------------------------------

Reporter: Tim Graham | Owner: nobody
Type: Bug | Status: new
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------+------------------------------------
Changes (by Claude Paroz):

* has_patch: 0 => 1


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

Django

unread,
Mar 25, 2020, 3:15:51 PM3/25/20
to django-...@googlegroups.com
#31399: SchemaEditor._alter_field() looks for foreign key constraints even if the
database doesn't support them.
----------------------------+---------------------------------------------
Reporter: Tim Graham | Owner: Tim Graham
Type: Bug | Status: assigned
Component: Migrations | Version: master
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------+---------------------------------------------
Changes (by felixxm):

* owner: nobody => Tim Graham
* status: new => assigned
* stage: Accepted => Ready for checkin


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

Django

unread,
Mar 25, 2020, 3:50:08 PM3/25/20
to django-...@googlegroups.com
#31399: SchemaEditor._alter_field() looks for foreign key constraints even if the
database doesn't support them.
----------------------------+---------------------------------------------
Reporter: Tim Graham | Owner: Tim Graham
Type: Bug | Status: closed
Component: Migrations | Version: master
Severity: Normal | Resolution: fixed

Keywords: | Triage Stage: Ready for checkin
Has patch: 1 | Needs documentation: 0

Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
----------------------------+---------------------------------------------
Changes (by Mariusz Felisiak <felisiak.mariusz@…>):

* status: assigned => closed
* resolution: => fixed


Comment:

In [changeset:"8bebb8f126aae3334da78339ccc4ded0f35692df" 8bebb8f1]:
{{{
#!CommitTicketReference repository=""
revision="8bebb8f126aae3334da78339ccc4ded0f35692df"
Fixed #31399 -- Made SchemaEditor._alter_field() ignore foreign key
constraints if unsupported.
}}}

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

Reply all
Reply to author
Forward
0 new messages