get_class fails with top level packages. #614
Closed
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Hello.
In an attemp to extend the shipping "app" we came into a problem.
We copied the shipping package into our project's package. So we have
MyProject/
shipping/
repository.py
MyProject/
settings.py
....
But after several tries and debugging, the get_class (and more precisely, get_classes) in oscar/core/loading.py was not picking the classes in this package and son, it defaulted to the oscar's system wide shipping module.
After a grep in oscar, it seems that everytime that Repository is required, it is loaded with get_classs. So it should not need any additional bonding other than overriding in INSTALLED_APPS:
INSTALLED_APPS = INSTALLED_APPS + get_core_apps(['shipping'])
It turns out that when get_classes generating the module path, if it is a top level package, it will generate something like : shipping.shipping.repository instead of shipping.repository.
The problem is that _get_app_module_path assumes there's always a dot in the module's name. get_classes should check that there is a dot in the module label before calling _get_app_module_path.