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)
Change History (5)
comment:1 by , 13 years ago
by , 13 years ago
Attachment: | importutils.diff added |
---|
comment:2 by , 13 years ago
Component: | Uncategorized → Core (Other) |
---|---|
Triage Stage: | Unreviewed → Accepted |
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 , 12 years ago
Wasn't this fixed by 7c5b2448?
I'm not sure I understand correctly the scope of this ticket.
comment:4 by , 12 years ago
Resolution: | → duplicate |
---|---|
Status: | new → closed |
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.
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.