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

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

Comments

Projects
None yet
1 participant
@muhammad-ammar

@rbarrois
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 https://github.com/rbarrois/factory_boy/blob/v2.5.2/factory/django.py#L64. This line was present in factory_boy==2.5.1 at https://github.com/rbarrois/factory_boy/blob/v2.5.1/factory/django.py#L95 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

        else:
            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