Code

Opened 4 years ago

Closed 4 years ago

Last modified 4 years ago

#14381 closed (fixed)

small improvement in db.utils.ConnectionRouter.__init__

Reported by: dauerbaustelle Owned by: nobody
Component: Database layer (models, ORM) Version: 1.2
Severity: Keywords:
Cc: Triage Stage: Ready for checkin
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: UI/UX:

Description

Raising an ImproperlyConfigured error if a configured Router class throws an AttributeError is confusing. Here's a patch:

diff -r 48bc10d49321 django/db/utils.py
--- a/django/db/utils.py        Fri Sep 10 12:25:58 2010 +0200
+++ b/django/db/utils.py        Sun Oct 03 13:58:35 2010 +0200
@@ -111,9 +111,11 @@
                 except ImportError, e:
                     raise ImproperlyConfigured('Error importing database router %s: "%s"' % (klass_name, e))
                 try:
-                    router = getattr(module, klass_name)()
+                    router = getattr(module, klass_name)
                 except AttributeError:
                     raise ImproperlyConfigured('Module "%s" does not define a database router name "%s"' % (module, klass_name))
+                else:
+                    router = router()
             else:
                 router = r
             self.routers.append(router)

Attachments (1)

django-14381.diff (808 bytes) - added by Alex 4 years ago.
Turned it into a diff.

Download all attachments as: .zip

Change History (4)

Changed 4 years ago by Alex

Turned it into a diff.

comment:1 Changed 4 years ago by lrekucki

  • Needs documentation unset
  • Needs tests unset
  • Patch needs improvement unset
  • Triage Stage changed from Unreviewed to Ready for checkin

Looks good. As it's very simple, going to mark as RFC.

comment:2 Changed 4 years ago by russellm

  • Resolution set to fixed
  • Status changed from new to closed

(In [14005]) Fixed #14381 -- Clarified exception handling when instantiating Routers. Thanks to dauerbaustelle for the suggestion and patch.

comment:3 Changed 4 years ago by russellm

(In [14008]) [1.2.X] Fixed #14381 -- Clarified exception handling when instantiating Routers. Thanks to dauerbaustelle for the suggestion and patch.

Backport of r14005 from trunk.

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.