Exceptions used for program logic db/utils.py load_backend
|Reported by:||Owned by:||nobody|
|Component:||Database layer (models, ORM)||Version:||1.2|
|Has patch:||no||Needs documentation:||no|
|Needs tests:||no||Patch needs improvement:||no|
I noticed this problem when trying to figure out why one of my views wouldn't load. The problem there seems to be that it catches both ImportErrors and AttributeErrors in the same catch. I tried modifying the code to explode at when import_module calls import instead but then Django stopped working.
This is because of how db/utils.py's load_backend tries to determine if you have used a non-package-prefixed name when specifying your db backend. load_backend does this by blindly prefixing the provded backend name with django.db.backends and then importing it. If the import succeeds Django thinks you used the short name and if it fails Django thinks you specified the prefixed name.
It would probably have been better to just check if the module name begins with django.db.backends or not instead of relying on import success/failure?