Commit d3bbb86f by bmedx

Shims to fix test collection errors

parent f3f8d8ec
...@@ -19,6 +19,9 @@ def run(): ...@@ -19,6 +19,9 @@ def run():
NOTE: DO **NOT** add additional code to this method or this file! The Platform Team 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. 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() django.setup()
...@@ -116,9 +116,10 @@ class SAMLProviderDataAdmin(admin.ModelAdmin): ...@@ -116,9 +116,10 @@ class SAMLProviderDataAdmin(admin.ModelAdmin):
def get_readonly_fields(self, request, obj=None): def get_readonly_fields(self, request, obj=None):
if obj: # editing an existing object 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 return self.readonly_fields
admin.site.register(SAMLProviderData, SAMLProviderDataAdmin) admin.site.register(SAMLProviderData, SAMLProviderDataAdmin)
......
...@@ -257,14 +257,9 @@ class XBlockFieldBase(models.Model): ...@@ -257,14 +257,9 @@ class XBlockFieldBase(models.Model):
modified = models.DateTimeField(auto_now=True, db_index=True) modified = models.DateTimeField(auto_now=True, db_index=True)
def __unicode__(self): def __unicode__(self):
return u'{}<{!r}'.format( # pylint: disable=protected-access
self.__class__.__name__, 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})
key: getattr(self, key)
for key in self._meta.get_all_field_names()
if key not in ('created', 'modified')
}
)
class XModuleUserStateSummaryField(XBlockFieldBase): class XModuleUserStateSummaryField(XBlockFieldBase):
......
...@@ -8,7 +8,6 @@ from django.conf import settings ...@@ -8,7 +8,6 @@ from django.conf import settings
from openedx.core.djangoapps.monkey_patch import django_db_models_options from openedx.core.djangoapps.monkey_patch import django_db_models_options
# Force settings to run so that the python path is modified # Force settings to run so that the python path is modified
settings.INSTALLED_APPS # pylint: disable=pointless-statement settings.INSTALLED_APPS # pylint: disable=pointless-statement
...@@ -19,6 +18,9 @@ def run(): ...@@ -19,6 +18,9 @@ def run():
NOTE: DO **NOT** add additional code to this method or this file! The Platform Team 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. 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() django.setup()
...@@ -36,13 +36,14 @@ class NoneToEmptyQuerySet(models.query.QuerySet): ...@@ -36,13 +36,14 @@ class NoneToEmptyQuerySet(models.query.QuerySet):
""" """
def _filter_or_exclude(self, *args, **kwargs): def _filter_or_exclude(self, *args, **kwargs):
# pylint: disable=protected-access # pylint: disable=protected-access
for name in self.model._meta.get_all_field_names(): for field_object in self.model._meta.get_fields():
field_object, _model, direct, _m2m = self.model._meta.get_field_by_name(name) direct = not field_object.auto_created or field_object.concrete
if direct and hasattr(field_object, 'Empty'): if direct and hasattr(field_object, 'Empty'):
for suffix in ('', '_exact'): for suffix in ('', '_exact'):
key = '{}{}'.format(name, suffix) key = '{}{}'.format(field_object.name, suffix)
if key in kwargs and kwargs[key] is None: if key in kwargs and kwargs[key] is None:
kwargs[key] = field_object.Empty kwargs[key] = field_object.Empty
return super(NoneToEmptyQuerySet, self)._filter_or_exclude(*args, **kwargs) return super(NoneToEmptyQuerySet, self)._filter_or_exclude(*args, **kwargs)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment