Opened 2 years ago

Closed 2 years ago

Last modified 2 years ago

#33288 closed Cleanup/optimization (fixed)

SQLite schema introspection should use PRAGMA instead of parsing to retrieve foreign keys

Reported by: Simon Charette Owned by: nobody
Component: Database layer (models, ORM) Version: dev
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

The SQLite backend's DatabaseIntrospection.get_relations uses a complex combination of regexes to extract foreign key constraints from DDL while PRAGMA foreign_key_list works just fine as _get_foreign_key_constraints.

Change History (7)

comment:1 by Simon Charette, 2 years ago

Has patch: set
Version: 3.2dev

comment:2 by Mariusz Felisiak, 2 years ago

Triage Stage: UnreviewedAccepted

comment:3 by Mariusz Felisiak, 2 years ago

Summary: SQLite schema introspection layer should use PRAGMA instead of parsing to retrieve foreign keysSQLite schema introspection should use PRAGMA instead of parsing to retrieve foreign keys

comment:4 by Mariusz Felisiak, 2 years ago

Triage Stage: AcceptedReady for checkin

comment:5 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 30ec7fe:

Refs #33288 -- Made SQLite introspection raise DatabaseError on nonexistent tables.

All the other backends behave this way and we had to make adjustments
to our test suite to account for this discrepancy.

This also allows SQLite's get_relations() not to raise on a nonexistent
table while making sure the InspectDBTestCase.test_introspection_errors
test which ensures an error during introspection is surfaced in
generated models files still passes.

comment:6 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

Resolution: fixed
Status: assignedclosed

In 483e30c3:

Fixed #33288 -- Made SQLite introspection use information schema for relations.

Previous solution was using brittle and complex parsing rules to
extract them from the SQL used to define the tables.

Removed a now unnecessary unit test that ensured the removed parsing
logic accounted for optional spacing.

comment:7 by Mariusz Felisiak <felisiak.mariusz@…>, 2 years ago

In 560ff988:

Refs #33288 -- Removed SQLite's DatabaseIntrospection._get_foreign_key_constraints().

The get_relations() method returns the exact same data in a more generic
format.

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