Commit 31f11709 by bmedx

Change OpaqueKeyField's get_prep_lookup to a Lookup

get_prep_lookup in a Field is deprecated in Django 1.11. This is the new way of doing this check.
parent 68890dab
......@@ -6,6 +6,7 @@ import warnings
from django.core.exceptions import ValidationError
from django.db import models
from django.db.models.lookups import IsNull
from opaque_keys.edx.keys import BlockTypeKey, CourseKey, UsageKey
from openedx.core.djangoapps.util.model_utils import CreatorMixin
from xmodule.modulestore.django import modulestore
......@@ -116,16 +117,6 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
else:
return value
def get_prep_lookup(self, lookup, value):
if lookup == 'isnull':
raise TypeError('Use {0}.Empty rather than None to query for a missing {0}'.format(self.__class__.__name__))
return super(OpaqueKeyField, self).get_prep_lookup(
lookup,
# strip key before comparing
_strip_value(value, lookup)
)
def get_prep_value(self, value):
if value is self.Empty or value is None:
return '' # CharFields should use '' as their empty value, rather than None
......@@ -159,6 +150,19 @@ class OpaqueKeyField(CreatorMixin, models.CharField):
return super(OpaqueKeyField, self).run_validators(value)
class OpaqueKeyFieldEmptyLookupIsNull(IsNull):
"""
This overrides the default __isnull model filter to help enforce the special way
we handle null / empty values in OpaqueKeyFields.
"""
def get_prep_lookup(self):
raise TypeError("Use this field's .Empty member rather than None or __isnull "
"to query for missing objects of this type.")
OpaqueKeyField.register_lookup(OpaqueKeyFieldEmptyLookupIsNull)
class CourseKeyField(OpaqueKeyField):
"""
A django Field that stores a CourseKey object as a string.
......
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