#30071: Obscure error message when no default db provided
--------------------------------------------+------------------------
Reporter: Benjy Weinberger | Owner: nobody
Type: Uncategorized | Status: new
Component: Uncategorized | Version: 2.1
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 1
Needs documentation: 0 | Needs tests: 0
Patch needs improvement: 0 | Easy pickings: 0
UI/UX: 0 |
--------------------------------------------+------------------------
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).
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.
--
Ticket URL: <https://code.djangoproject.com/ticket/30071>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
--
You received this message because you are subscribed to the Google Groups
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/049.985f99272510b5ea05114f880e3eaa6a%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.