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

import get_model when needed #228

muhammad-ammar opened this Issue Sep 3, 2015 · 0 comments


None yet
1 participant

We run some of our tests without django settings but factory_boy==2.5.2 tries to load Django settings due which we are getting lots of errors. Please see This line was present in factory_boy==2.5.1 at but _load_model_class was never called so there were no issue.

Any suggestion to solve the issue?

Below is what i have in mind that can hopefully solve this

get_model_func = None
def get_model(app, model):
    global get_model_func
    if get_model_func is None:
        if django is None:
            raise import_failure

        elif django.VERSION[:2] < (1, 7):
            from django.db.models import loading
            get_model_func = loading.get_model

            from django import apps as django_apps
            get_model_func = django_apps.apps.get_model

    return get_model_func(app, model)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment