Opened 13 years ago

Closed 12 years ago

#16675 closed Cleanup/optimization (duplicate)

Refactor the class/function loading code to use common API

Reported by: Jannis Leidel Owned by: nobody
Component: Core (Other) Version: 1.3
Severity: Normal Keywords:
Cc: Triage Stage: Accepted
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

There are countless code snippets in Django that load a particular callback or backend and each handle the possible exceptions differently.

I think for the most of those examples we can use a common API which would lower the chance of breakage as well be useful to users.

Jonas Obrist implemented this kind of thing in his django-load app (http://readthedocs.org/docs/django-load/en/latest/).

Attachments (1)

importutils.diff (5.8 KB ) - added by Jannis Leidel 13 years ago.
diff from https://github.com/jezdez/django/compare/feature/importutils

Download all attachments as: .zip

Change History (5)

comment:1 by Jannis Leidel, 13 years ago

I've updated Jonas' code slightly and added it to the django.utils.importlib module.

https://github.com/jezdez/django/compare/feature/importutils

If accepted, this would require more work on the actual code parts where imports are done.

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

Component: UncategorizedCore (Other)
Triage Stage: UnreviewedAccepted

I'll accept this in principle -- the "load a backend" pattern is something that we've reimplemented far too many times. If we can pull this back to a common API without losing all the edge cases, it seems like a no-brainer to me.

From a first inspection, this snippet from Jonas looks like a good approach to me -- I'd just need to see it in use for a couple of actual use cases to be 100% convinced.

comment:3 by Aymeric Augustin, 12 years ago

Wasn't this fixed by 7c5b2448?

I'm not sure I understand correctly the scope of this ticket.

comment:4 by Claude Paroz, 12 years ago

Resolution: duplicate
Status: newclosed

I wasn't aware of this ticket when I committed [7c5b2448] (#17061). If the possibility to customize the raised exception is needed somewhere in Django, we can always add it at a later stage.

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