Russell Keith-Magee wrote:
> On 8/30/07, George Vilches <[EMAIL PROTECTED]> wrote:
>> Folks,
>>
>> Now that the database backend refactoring has landed, and DB
>> functionality is really easy to extend, how does everyone feel about the
>> possibility of allowing people to specify their own database backends
>> within their projects (i.e., without modifying the Django source tree in
>> any way?) I see this as an excellent way for people to increase their
>
> The broad idea seems reasonable to me. There's no point having an
> easily pluggable database engine if you can't plug in your own
> database :-)
>
> Regarding the approach - I'm inclined to prefer #1. It's simple and
> easy to explain, and I don't see that there is that much potential for
> side effects. The only clash I can forsee is if you had your own
> toplevel module that mirrored the backend names of Django - this
> doesn't really strike me as something that will be a common problem,
> and if it is, the solution is easy (rename the clashing external
> module).
Then in this spirit, my patch (against r6049) is at the end of the
message. Notice that the only real change is:
try:
backend = __import__('%s.base' % settings.DATABASE_ENGINE, {},
{}, [''])
except ImportError, e_user:
Everything else is just an indentation correction (it moves the current
error checking under the second import error). The flow of this allows
the internal packages to still be checked first, and then it tries to
import the package directly without the django.db.backends prefix. If
that doesn't work, the error message and handling is exactly as it used
to be.
I've tried it in several existing situations, seems to hold up fine with
existing Django DB backends and finds and imports new backends properly
(and properly errors if it can't do either). Anyone have additional
thoughts on this approach to having replaceable backends, or is this
good as is?
Thanks,
George
Index: django/db/__init__.py
===================================================================
--- django/db/__init__.py (revision 6049)
+++ django/db/__init__.py (working copy)
@@ -10,18 +10,21 @@
try:
backend = __import__('django.db.backends.%s.base' %
settings.DATABASE_ENGINE, {}, {}, [''])
except ImportError, e:
- # The database backend wasn't found. Display a helpful error message
- # listing all possible database backends.
- from django.core.exceptions import ImproperlyConfigured
- import os
- backend_dir = os.path.join(__path__[0], 'backends')
- available_backends = [f for f in os.listdir(backend_dir) if not
f.startswith('_') and not f.startswith('.') and not f.endswith('.py')
and not f.endswith('.pyc')]
- available_backends.sort()
- if settings.DATABASE_ENGINE not in available_backends:
- raise ImproperlyConfigured, "%r isn't an available database
backend. Available options are: %s" % \
- (settings.DATABASE_ENGINE, ", ".join(map(repr,
available_backends)))
- else:
- raise # If there's some other error, this must be an error in
Django itself.
+ try:
+ backend = __import__('%s.base' % settings.DATABASE_ENGINE, {},
{}, [''])
+ except ImportError, e_user:
+ # The database backend wasn't found. Display a helpful error
message
+ # listing all possible database backends.
+ from django.core.exceptions import ImproperlyConfigured
+ import os
+ backend_dir = os.path.join(__path__[0], 'backends')
+ available_backends = [f for f in os.listdir(backend_dir) if not
f.startswith('_') and not f.startswith('.') and not f.endswith('.py')
and not f.endswith('.pyc')]
+ available_backends.sort()
+ if settings.DATABASE_ENGINE not in available_backends:
+ raise ImproperlyConfigured, "%r isn't an available database
backend. Available options are: %s" % \
+ (settings.DATABASE_ENGINE, ", ".join(map(repr,
available_backends)))
+ else:
+ raise # If there's some other error, this must be an error
in Django itself.
get_introspection_module = lambda:
__import__('django.db.backends.%s.introspection' %
settings.DATABASE_ENGINE, {}, {}, [''])
get_creation_module = lambda:
__import__('django.db.backends.%s.creation' % settings.DATABASE_ENGINE,
{}, {}, [''])
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-developers?hl=en
-~----------~----~----~----~------~----~------~--~---