Opened 14 years ago

Closed 14 years ago

Last modified 14 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: no UI/UX: no

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 Gaynor 14 years ago.
Turned it into a diff.

Download all attachments as: .zip

Change History (4)

by Alex Gaynor, 14 years ago

Attachment: django-14381.diff added

Turned it into a diff.

comment:1 by Łukasz Rekucki, 14 years ago

Triage Stage: UnreviewedReady for checkin

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

comment:2 by Russell Keith-Magee, 14 years ago

Resolution: fixed
Status: newclosed

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

comment:3 by Russell Keith-Magee, 14 years ago

(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.

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