Loading Backends

2 views
Skip to first unread message

Marty Alchin

unread,
Dec 21, 2009, 9:22:24 AM12/21/09
to django-d...@googlegroups.com
Looking over Simon's patch for signed cookies, I noticed that yet
another feature needs to write its own "load a backend from a setting"
function. A quick search of the codebase shows at least four other
instances of this behavior (shown below), and it seems it's only going
to get more common going forward. Is there a way we can factor some of
this out into a utility? As it stands now, the author of each feature
needs to figure out which one to copy from, which means figure out how
they're different, even though many of those differences are just
stylistic.

django.contrib.auth.load_backend()
django.core.files.storage.get_storage_class()
django.template.loader.find_template_loader()
django.db.load_backend()

Database loaders are a bit of an oddball, since they load an entire
module's worth of classes based on the setting, but there's repetition
even there. Unfortunately, I can't dedicate much of my own time at the
moment to look into this, but I think it'd be worth doing before we
start adding even more features with configurable backends in the
future.

-Marty

Jeremy Dunck

unread,
Dec 21, 2009, 9:39:12 AM12/21/09
to django-d...@googlegroups.com
On Mon, Dec 21, 2009 at 8:22 AM, Marty Alchin <gulo...@gmail.com> wrote:
...
> django.contrib.auth.load_backend()
> django.core.files.storage.get_storage_class()
> django.template.loader.find_template_loader()
> django.db.load_backend()

Also, django.core.cache.get_cache

Russell Keith-Magee

unread,
Dec 21, 2009, 10:32:22 AM12/21/09
to django-d...@googlegroups.com

Also django.core.email, django.contrib.messages,
django.contrib.sessions... the list goes on.

The difficulty is that they aren't all exactly the same:

* The email backend loader take arguments that configure the
underlying mail connection

* The cache backend needs to handle a URI-style definition.

* The template loaders need to have fallback support for old-style
template loaders, as well as handling checks for whether the loader is
available in the current environment.

Similar eccentricities exist in many of the backends.

In short - yes, factoring this out into a common utility is desirable.
However, it's a lot easier said than done.

Yours,
Russ Magee %-)

Simon Willison

unread,
Dec 21, 2009, 10:46:53 AM12/21/09
to Django developers
On Dec 21, 2:22 pm, Marty Alchin <gulop...@gmail.com> wrote:
> Looking over Simon's patch for signed cookies, I noticed that yet
> another feature needs to write its own "load a backend from a setting"
> function.

Yup - and as I copied and pasted it from somewhere else I thought
exactly the same thing. Is this kind of refactoring something we can
do after the 1.2 feature freeze? If so I think it would be worth
cleaning up at least some of this stuff.

Cheers,

Simon

Marty Alchin

unread,
Dec 21, 2009, 10:54:00 AM12/21/09
to django-d...@googlegroups.com

Absolutely, this is completely separate from anything that should
affect the feature freeze. As Russ pointed out, there are a lot of
different of this backend loading stuff, so it'll be tricky to figure
out just how much can/should be factored out, how to deal with some of
the variations and how to recommend people do it going forward. In
fact, it's not even something that needs to happen by the 1.2 release
at all, if more time is necessary to get it right. It's less than
ideal at the moment, but I'd say practicality beats purity in this
case, to make sure we can get the goods out the door.

-Marty

Reply all
Reply to author
Forward
0 new messages