Opened 12 years ago

Closed 12 years ago

#19677 closed Bug (fixed)

SQLite can't introspect recursive fks

Reported by: Simon Charette Owned by: Aymeric Augustin
Component: Database layer (models, ORM) Version: dev
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

SQLite's get_key_columns relies on the presence of inline REFERENCES clauses in table definitions to work properly.

However, since those are not created by BaseDatabaseCreation.sql_for_inline_foreign_key_references for recursive fks and there's no support for foreign keys on SQLite yet, sql_for_pending_references does nothing.

I'm attaching a patch that makes sure to add references on table creation with introspection assertions. It passes on all elements of product(['Python 2.7.3 ', 'Python 3.2.3 '], ['SQLite3', 'Postgresql 9.1'])

I stumbled upon this issue while trying to write tests for #19676 under a TestCase which @skipUnlessDBFeature('can_introspect_foreign_keys').

Attachments (1)

0001-Fixed-19677-Create-inline-references-for-recursive-f.patch (4.5 KB ) - added by Simon Charette 12 years ago.

Download all attachments as: .zip

Change History (4)

comment:1 by Aymeric Augustin, 12 years ago

Component: ORM aggregationDatabase layer (models, ORM)
Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

Tests don't pass out of the box but it appears to be a simple ordering issue:

(django-dev)myk@mYk tests % PYTHONPATH=.. python runtests.py --settings=test_mysql_local inspectdb introspection        ~/Documents/dev/django/tests
Creating test database for alias 'default'...
Creating test database for alias 'other'...
........F.......s..
======================================================================
FAIL: test_get_key_columns (regressiontests.introspection.tests.IntrospectionTests)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "/Users/myk/Documents/dev/django/django/test/testcases.py", line 873, in skip_wrapper
    return test_func(*args, **kwargs)
  File "/Users/myk/Documents/dev/django/tests/regressiontests/introspection/tests.py", line 117, in test_get_key_columns
    ('response_to_id', Article._meta.db_table, 'id')])
AssertionError: Lists differ: [(u'response_to_id', u'introsp... != [(u'reporter_id', u'introspect...

First differing element 0:
(u'response_to_id', u'introspection_article', u'id')
(u'reporter_id', u'introspection_reporter', u'id')

+ [(u'reporter_id', u'introspection_reporter', u'id'),
- [(u'response_to_id', u'introspection_article', u'id'),
? ^                                                    ^

+  (u'response_to_id', u'introspection_article', u'id')]
? ^                                                    ^

-  (u'reporter_id', u'introspection_reporter', u'id')]

----------------------------------------------------------------------
Ran 19 tests in 0.226s

FAILED (failures=1, skipped=1)
Destroying test database for alias 'default'...
Destroying test database for alias 'other'...

comment:2 by Aymeric Augustin, 12 years ago

Owner: changed from nobody to Aymeric Augustin
Status: newassigned

I'll update the test and commit the patch.

comment:3 by Aymeric Augustin <aymeric.augustin@…>, 12 years ago

Resolution: fixed
Status: assignedclosed

In f46d7314b50d71a75f51ebae9c5957cb96b11bd9:

Fixed #19677 -- Introspection of recursive foreign keys under SQLite.

Thanks Simon Charette.

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