From d3bbb86fe306c7b67ec53494586e8fc291ec154d Mon Sep 17 00:00:00 2001 From: bmedx Date: Thu, 9 Nov 2017 13:34:28 -0500 Subject: [PATCH] Shims to fix test collection errors --- cms/startup.py | 5 ++++- common/djangoapps/third_party_auth/admin.py | 3 ++- lms/djangoapps/courseware/models.py | 11 +++-------- lms/startup.py | 6 ++++-- openedx/core/djangoapps/xmodule_django/models.py | 7 ++++--- 5 files changed, 17 insertions(+), 15 deletions(-) diff --git a/cms/startup.py b/cms/startup.py index ca1c37074a..a791a3a953 100644 --- a/cms/startup.py +++ b/cms/startup.py @@ -19,6 +19,9 @@ def run(): NOTE: DO **NOT** add additional code to this method or this file! The Platform Team is moving all startup code to more standard locations using Django best practices. """ - django_db_models_options.patch() + # TODO: Remove Django 1.11 upgrade shim + # SHIM: We should be able to get rid of this monkey patch post-upgrade + if django.VERSION[0] == 1 and django.VERSION[1] < 10: + django_db_models_options.patch() django.setup() diff --git a/common/djangoapps/third_party_auth/admin.py b/common/djangoapps/third_party_auth/admin.py index b3d19095c8..b51b98eb9b 100644 --- a/common/djangoapps/third_party_auth/admin.py +++ b/common/djangoapps/third_party_auth/admin.py @@ -116,9 +116,10 @@ class SAMLProviderDataAdmin(admin.ModelAdmin): def get_readonly_fields(self, request, obj=None): if obj: # editing an existing object - return self.model._meta.get_all_field_names() # pylint: disable=protected-access + return [field.name for field in self.model._meta.get_fields()] # pylint: disable=protected-access return self.readonly_fields + admin.site.register(SAMLProviderData, SAMLProviderDataAdmin) diff --git a/lms/djangoapps/courseware/models.py b/lms/djangoapps/courseware/models.py index e35d31357a..8c84ef4781 100644 --- a/lms/djangoapps/courseware/models.py +++ b/lms/djangoapps/courseware/models.py @@ -257,14 +257,9 @@ class XBlockFieldBase(models.Model): modified = models.DateTimeField(auto_now=True, db_index=True) def __unicode__(self): - return u'{}<{!r}'.format( - self.__class__.__name__, - { - key: getattr(self, key) - for key in self._meta.get_all_field_names() - if key not in ('created', 'modified') - } - ) + # pylint: disable=protected-access + keys = [field.name for field in self._meta.get_fields() if field.name not in ('created', 'modified')] + return u'{}<{!r}'.format(self.__class__.__name__, {key: getattr(self, key) for key in keys}) class XModuleUserStateSummaryField(XBlockFieldBase): diff --git a/lms/startup.py b/lms/startup.py index 49a8ff293b..f1326f0a49 100644 --- a/lms/startup.py +++ b/lms/startup.py @@ -8,7 +8,6 @@ from django.conf import settings from openedx.core.djangoapps.monkey_patch import django_db_models_options # Force settings to run so that the python path is modified - settings.INSTALLED_APPS # pylint: disable=pointless-statement @@ -19,6 +18,9 @@ def run(): NOTE: DO **NOT** add additional code to this method or this file! The Platform Team is moving all startup code to more standard locations using Django best practices. """ - django_db_models_options.patch() + # TODO: Remove Django 1.11 upgrade shim + # SHIM: We should be able to get rid of this monkey patch post-upgrade + if django.VERSION[0] == 1 and django.VERSION[1] < 10: + django_db_models_options.patch() django.setup() diff --git a/openedx/core/djangoapps/xmodule_django/models.py b/openedx/core/djangoapps/xmodule_django/models.py index 548c57321f..f9d12c8504 100644 --- a/openedx/core/djangoapps/xmodule_django/models.py +++ b/openedx/core/djangoapps/xmodule_django/models.py @@ -36,13 +36,14 @@ class NoneToEmptyQuerySet(models.query.QuerySet): """ def _filter_or_exclude(self, *args, **kwargs): # pylint: disable=protected-access - for name in self.model._meta.get_all_field_names(): - field_object, _model, direct, _m2m = self.model._meta.get_field_by_name(name) + for field_object in self.model._meta.get_fields(): + direct = not field_object.auto_created or field_object.concrete if direct and hasattr(field_object, 'Empty'): for suffix in ('', '_exact'): - key = '{}{}'.format(name, suffix) + key = '{}{}'.format(field_object.name, suffix) if key in kwargs and kwargs[key] is None: kwargs[key] = field_object.Empty + return super(NoneToEmptyQuerySet, self)._filter_or_exclude(*args, **kwargs)