[Django] #27372: Inspectdb fails to inspect sqlite3 tables with foreign keys

24 views
Skip to first unread message

Django

unread,
Oct 22, 2016, 7:17:38 AM10/22/16
to django-...@googlegroups.com
#27372: Inspectdb fails to inspect sqlite3 tables with foreign keys
----------------------------------------------+--------------------
Reporter: samuller | Owner: nobody
Type: Bug | Status: new
Component: Database layer (models, ORM) | Version: 1.10
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
----------------------------------------------+--------------------
Running `python manage.py inspectdb` on an sqlite3 database with the
following schema:

{{{#!sql
CREATE TABLE table_1 (
id INTEGER PRIMARY KEY AUTOINCREMENT
);

CREATE TABLE table_2 (
id INTEGER PRIMARY KEY AUTOINCREMENT,
foreign_key_col INTEGER,
FOREIGN KEY (foreign_key_col) REFERENCES table_1(id)
);
}}}
results in output missing tables with foreign keys:
{{{#!python
class Table1(models.Model):
id = models.IntegerField(primary_key=True, blank=True, null=True) #
AutoField?

class Meta:
managed = False
db_table = 'table_1'
# Unable to inspect table 'table_2'
# The error was: 'NoneType' object has no attribute 'groups'
}}}

It turns out the regular expression (in
django/db/backends/sqlite3/introspection.py) is not matching the string
"FOREIGN KEY (foreign_key_col) REFERENCES table_1(id)" due to the single
space character between KEY and the bracket. Depending on the schema input
used to create the table there could be any amount of whitespace there.

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

Django

unread,
Oct 22, 2016, 7:18:45 AM10/22/16
to django-...@googlegroups.com
#27372: Inspectdb fails to inspect sqlite3 tables with foreign keys
-------------------------------------+-------------------------------------

Reporter: samuller | Owner: nobody
Type: Bug | Status: new
Component: Database layer | Version: 1.10
(models, ORM) |
Severity: Normal | Resolution:
Keywords: | Triage Stage:
| Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 1 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by samuller):

* needs_better_patch: => 0
* needs_tests: => 0
* easy: 0 => 1
* needs_docs: => 0


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

Django

unread,
Oct 22, 2016, 8:11:45 AM10/22/16
to django-...@googlegroups.com
#27372: inspectdb fails to inspect sqlite3 tables with foreign keys that have
spaces
-------------------------------------+-------------------------------------

Reporter: samuller | Owner: nobody
Type: Bug | Status: new
Component: Core (Management | Version: 1.10
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham):

* component: Database layer (models, ORM) => Core (Management commands)
* needs_tests: 0 => 1
* easy: 1 => 0
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


Comment:

[https://github.com/django/django/pull/7402 PR] (currently missing a test)

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

Django

unread,
Nov 5, 2016, 6:58:54 AM11/5/16
to django-...@googlegroups.com
#27372: inspectdb fails to inspect sqlite3 tables with foreign keys that have
spaces
-------------------------------------+-------------------------------------
Reporter: samuller | Owner: Saulius
| Žemaitaitis
Type: Bug | Status: assigned

Component: Core (Management | Version: 1.10
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Saulius Žemaitaitis):

* owner: nobody => Saulius Žemaitaitis
* status: new => assigned


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

Django

unread,
Nov 5, 2016, 9:08:04 AM11/5/16
to django-...@googlegroups.com
#27372: inspectdb fails to inspect sqlite3 tables with foreign keys that have
spaces
-------------------------------------+-------------------------------------
Reporter: samuller | Owner: (none)
Type: Bug | Status: new

Component: Core (Management | Version: 1.10
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Saulius Žemaitaitis):

* owner: Saulius Žemaitaitis => (none)
* status: assigned => new
* needs_tests: 1 => 0


Comment:

[https://github.com/django/django/pull/7486 PR]

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

Django

unread,
Nov 5, 2016, 8:51:22 PM11/5/16
to django-...@googlegroups.com
#27372: inspectdb fails to inspect sqlite3 tables with foreign keys that have
spaces
-------------------------------------+-------------------------------------
Reporter: samuller | Owner: (none)
Type: Bug | Status: new

Component: Core (Management | Version: 1.10
commands) |
Severity: Normal | Resolution:
Keywords: | Triage Stage: Ready for
| checkin

Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Michael Manfre):

* stage: Accepted => Ready for checkin


Comment:

Patch now has a test and looks good.

--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:5>

Django

unread,
Nov 6, 2016, 4:14:09 AM11/6/16
to django-...@googlegroups.com
#27372: inspectdb fails to inspect sqlite3 tables with foreign keys that have
spaces
-------------------------------------+-------------------------------------
Reporter: samuller | Owner: Tim
| Graham <timograham@…>
Type: Bug | Status: closed

Component: Core (Management | Version: 1.10
commands) |
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: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Tim Graham <timograham@…>):

* owner: (none) => Tim Graham <timograham@…>
* status: new => closed
* resolution: => fixed


Comment:

In [changeset:"f28d29e8b726b8b013e8739fab542a796f348e78" f28d29e8]:
{{{
#!CommitTicketReference repository=""
revision="f28d29e8b726b8b013e8739fab542a796f348e78"
Fixed #27372 -- Fixed introspection of SQLite foreign keys with spaces in
DDL.

Thanks samuller for the report and initial patch.
}}}

--
Ticket URL: <https://code.djangoproject.com/ticket/27372#comment:6>

Reply all
Reply to author
Forward
0 new messages