Opened 6 years ago

Closed 6 years ago

#30071 closed Bug (fixed)

Obscure error message when no default db provided

Reported by: Benjy Weinberger Owned by: Benjy Weinberger
Component: Database layer (models, ORM) Version: 2.1
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 (last modified by Benjy Weinberger)

In ConnectionHandler, the explicit check for the DEFAULT_DB_ALIAS
key in the databases dict comes only after an attempt to lookup that key.

If you have at least one non-default db, but no default db, no dummy
default will be created for you, and the DEFAULT_DB_ALIAS key will
not be present. Under these circumstances, referencing the databases
property directly will give a KeyError instead of the intended
ImproperlyConfigured error.

Worse, if you try to access a non-default db, ensure_defaults will
catch that KeyError but misinterpret it as being for the non-default
db name (which does in fact exist in the dict).

Change History (4)

comment:1 by Benjy Weinberger, 6 years ago

Component: UncategorizedDatabase layer (models, ORM)
Owner: changed from nobody to Benjy Weinberger
Status: newassigned

PR

This change moves the explicit check before the attempt to use the key,
so that no KeyError is ever raised for DEFAULT_DB_ALIAS. It adds
a test for this case, and also adds a test for the case where the
default db is explicitly set to an empty dict.

Last edited 6 years ago by Tim Graham (previous) (diff)

comment:3 by Benjy Weinberger, 6 years ago

Description: modified (diff)

comment:4 by Tim Graham, 6 years ago

Triage Stage: UnreviewedAccepted
Type: UncategorizedBug

comment:5 by Tim Graham <timograham@…>, 6 years ago

Resolution: fixed
Status: assignedclosed

In 222caab6:

Fixed #30071 -- Fixed error message when a 'default' database isn't provided.

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