Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

util.import_local fails on apps with compound paths #13

Closed
mhotwagner opened this issue Aug 14, 2017 · 1 comment
Closed

util.import_local fails on apps with compound paths #13

mhotwagner opened this issue Aug 14, 2017 · 1 comment

Comments

@mhotwagner
Copy link

The local import utility handles apps with simple paths (no-dot), but fails on apps with compound paths (ie, dots). So, this works fine:

INSTALLED_APPS = ('some_app',)
import_local('some_app.SomeClass')

But this fails:

INSTALLED_APPS = ('some_top_level_package.some_module')
import_local('some_top_level_package.some_module.SomeClass')

The issue lies here, in the import_local function:

def import_local(path_to_object)
    path, name = path_to_object.rsplit('.', 1)

    app = path.split('.')[0]  # Assumes the app is the 0th element of the path

    if app not in settings.INSTALLED_APPS:
        raise AssertionError()

Restricting possible app names to the 0th element of the path means we ignore apps with compound paths. Solution should check INSTALLED_APPS for all iterations of the path.

mhotwagner pushed a commit to mhotwagner/django-rest-framework-serializer-extensions that referenced this issue Aug 14, 2017
 - Checks all possible iterations of app name against `INSTALLED_APPS`, so `app.sub_app.module.Class` checks `INSTALLED_APPS` for `app.sub_app.module`, then `app.sub_app`, then `app`, instead of just checking for `app`.

 - Adds test to characterize new import behavior.

 - Fixes issue evenicoulddoit#13
@evenicoulddoit
Copy link
Owner

@mhotwagner Thanks for your patience - new version just pushed out with your changes in :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants