Opened 8 years ago
Closed 8 years ago
#27372 closed Bug (fixed)
inspectdb fails to inspect sqlite3 tables with foreign keys that have spaces
Reported by: | samuller | Owned by: | |
---|---|---|---|
Component: | Core (Management commands) | Version: | 1.10 |
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
Running python manage.py inspectdb
on an sqlite3 database with the following schema:
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:
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.
Change History (6)
comment:1 by , 8 years ago
Easy pickings: | set |
---|
comment:2 by , 8 years ago
Component: | Database layer (models, ORM) → Core (Management commands) |
---|---|
Easy pickings: | unset |
Has patch: | set |
Needs tests: | set |
Summary: | Inspectdb fails to inspect sqlite3 tables with foreign keys → inspectdb fails to inspect sqlite3 tables with foreign keys that have spaces |
Triage Stage: | Unreviewed → Accepted |
comment:3 by , 8 years ago
Owner: | changed from | to
---|---|
Status: | new → assigned |
comment:4 by , 8 years ago
Needs tests: | unset |
---|---|
Owner: | removed |
Status: | assigned → new |
PR with tests based on the patch by samuller.
comment:5 by , 8 years ago
Triage Stage: | Accepted → Ready for checkin |
---|
Patch now has a test and looks good.
PR (currently missing a test)