lookups.py 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655
  1. import itertools
  2. import math
  3. import warnings
  4. from copy import copy
  5. from django.core.exceptions import EmptyResultSet
  6. from django.db.models.expressions import Case, Exists, Func, Value, When
  7. from django.db.models.fields import (
  8. CharField, DateTimeField, Field, IntegerField, UUIDField,
  9. )
  10. from django.db.models.query_utils import RegisterLookupMixin
  11. from django.utils.datastructures import OrderedSet
  12. from django.utils.deprecation import RemovedInDjango40Warning
  13. from django.utils.functional import cached_property
  14. from django.utils.hashable import make_hashable
  15. class Lookup:
  16. lookup_name = None
  17. prepare_rhs = True
  18. can_use_none_as_rhs = False
  19. def __init__(self, lhs, rhs):
  20. self.lhs, self.rhs = lhs, rhs
  21. self.rhs = self.get_prep_lookup()
  22. if hasattr(self.lhs, 'get_bilateral_transforms'):
  23. bilateral_transforms = self.lhs.get_bilateral_transforms()
  24. else:
  25. bilateral_transforms = []
  26. if bilateral_transforms:
  27. # Warn the user as soon as possible if they are trying to apply
  28. # a bilateral transformation on a nested QuerySet: that won't work.
  29. from django.db.models.sql.query import ( # avoid circular import
  30. Query,
  31. )
  32. if isinstance(rhs, Query):
  33. raise NotImplementedError("Bilateral transformations on nested querysets are not implemented.")
  34. self.bilateral_transforms = bilateral_transforms
  35. def apply_bilateral_transforms(self, value):
  36. for transform in self.bilateral_transforms:
  37. value = transform(value)
  38. return value
  39. def batch_process_rhs(self, compiler, connection, rhs=None):
  40. if rhs is None:
  41. rhs = self.rhs
  42. if self.bilateral_transforms:
  43. sqls, sqls_params = [], []
  44. for p in rhs:
  45. value = Value(p, output_field=self.lhs.output_field)
  46. value = self.apply_bilateral_transforms(value)
  47. value = value.resolve_expression(compiler.query)
  48. sql, sql_params = compiler.compile(value)
  49. sqls.append(sql)
  50. sqls_params.extend(sql_params)
  51. else:
  52. _, params = self.get_db_prep_lookup(rhs, connection)
  53. sqls, sqls_params = ['%s'] * len(params), params
  54. return sqls, sqls_params
  55. def get_source_expressions(self):
  56. if self.rhs_is_direct_value():
  57. return [self.lhs]
  58. return [self.lhs, self.rhs]
  59. def set_source_expressions(self, new_exprs):
  60. if len(new_exprs) == 1:
  61. self.lhs = new_exprs[0]
  62. else:
  63. self.lhs, self.rhs = new_exprs
  64. def get_prep_lookup(self):
  65. if hasattr(self.rhs, 'resolve_expression'):
  66. return self.rhs
  67. if self.prepare_rhs and hasattr(self.lhs.output_field, 'get_prep_value'):
  68. return self.lhs.output_field.get_prep_value(self.rhs)
  69. return self.rhs
  70. def get_db_prep_lookup(self, value, connection):
  71. return ('%s', [value])
  72. def process_lhs(self, compiler, connection, lhs=None):
  73. lhs = lhs or self.lhs
  74. if hasattr(lhs, 'resolve_expression'):
  75. lhs = lhs.resolve_expression(compiler.query)
  76. return compiler.compile(lhs)
  77. def process_rhs(self, compiler, connection):
  78. value = self.rhs
  79. if self.bilateral_transforms:
  80. if self.rhs_is_direct_value():
  81. # Do not call get_db_prep_lookup here as the value will be
  82. # transformed before being used for lookup
  83. value = Value(value, output_field=self.lhs.output_field)
  84. value = self.apply_bilateral_transforms(value)
  85. value = value.resolve_expression(compiler.query)
  86. if hasattr(value, 'as_sql'):
  87. return compiler.compile(value)
  88. else:
  89. return self.get_db_prep_lookup(value, connection)
  90. def rhs_is_direct_value(self):
  91. return not hasattr(self.rhs, 'as_sql')
  92. def relabeled_clone(self, relabels):
  93. new = copy(self)
  94. new.lhs = new.lhs.relabeled_clone(relabels)
  95. if hasattr(new.rhs, 'relabeled_clone'):
  96. new.rhs = new.rhs.relabeled_clone(relabels)
  97. return new
  98. def get_group_by_cols(self, alias=None):
  99. cols = self.lhs.get_group_by_cols()
  100. if hasattr(self.rhs, 'get_group_by_cols'):
  101. cols.extend(self.rhs.get_group_by_cols())
  102. return cols
  103. def as_sql(self, compiler, connection):
  104. raise NotImplementedError
  105. def as_oracle(self, compiler, connection):
  106. # Oracle doesn't allow EXISTS() to be compared to another expression
  107. # unless it's wrapped in a CASE WHEN.
  108. wrapped = False
  109. exprs = []
  110. for expr in (self.lhs, self.rhs):
  111. if isinstance(expr, Exists):
  112. expr = Case(When(expr, then=True), default=False)
  113. wrapped = True
  114. exprs.append(expr)
  115. lookup = type(self)(*exprs) if wrapped else self
  116. return lookup.as_sql(compiler, connection)
  117. @cached_property
  118. def contains_aggregate(self):
  119. return self.lhs.contains_aggregate or getattr(self.rhs, 'contains_aggregate', False)
  120. @cached_property
  121. def contains_over_clause(self):
  122. return self.lhs.contains_over_clause or getattr(self.rhs, 'contains_over_clause', False)
  123. @property
  124. def is_summary(self):
  125. return self.lhs.is_summary or getattr(self.rhs, 'is_summary', False)
  126. @property
  127. def identity(self):
  128. return self.__class__, self.lhs, self.rhs
  129. def __eq__(self, other):
  130. if not isinstance(other, Lookup):
  131. return NotImplemented
  132. return self.identity == other.identity
  133. def __hash__(self):
  134. return hash(make_hashable(self.identity))
  135. class Transform(RegisterLookupMixin, Func):
  136. """
  137. RegisterLookupMixin() is first so that get_lookup() and get_transform()
  138. first examine self and then check output_field.
  139. """
  140. bilateral = False
  141. arity = 1
  142. @property
  143. def lhs(self):
  144. return self.get_source_expressions()[0]
  145. def get_bilateral_transforms(self):
  146. if hasattr(self.lhs, 'get_bilateral_transforms'):
  147. bilateral_transforms = self.lhs.get_bilateral_transforms()
  148. else:
  149. bilateral_transforms = []
  150. if self.bilateral:
  151. bilateral_transforms.append(self.__class__)
  152. return bilateral_transforms
  153. class BuiltinLookup(Lookup):
  154. def process_lhs(self, compiler, connection, lhs=None):
  155. lhs_sql, params = super().process_lhs(compiler, connection, lhs)
  156. field_internal_type = self.lhs.output_field.get_internal_type()
  157. db_type = self.lhs.output_field.db_type(connection=connection)
  158. lhs_sql = connection.ops.field_cast_sql(
  159. db_type, field_internal_type) % lhs_sql
  160. lhs_sql = connection.ops.lookup_cast(self.lookup_name, field_internal_type) % lhs_sql
  161. return lhs_sql, list(params)
  162. def as_sql(self, compiler, connection):
  163. lhs_sql, params = self.process_lhs(compiler, connection)
  164. rhs_sql, rhs_params = self.process_rhs(compiler, connection)
  165. params.extend(rhs_params)
  166. rhs_sql = self.get_rhs_op(connection, rhs_sql)
  167. return '%s %s' % (lhs_sql, rhs_sql), params
  168. def get_rhs_op(self, connection, rhs):
  169. return connection.operators[self.lookup_name] % rhs
  170. class FieldGetDbPrepValueMixin:
  171. """
  172. Some lookups require Field.get_db_prep_value() to be called on their
  173. inputs.
  174. """
  175. get_db_prep_lookup_value_is_iterable = False
  176. def get_db_prep_lookup(self, value, connection):
  177. # For relational fields, use the 'target_field' attribute of the
  178. # output_field.
  179. field = getattr(self.lhs.output_field, 'target_field', None)
  180. get_db_prep_value = getattr(field, 'get_db_prep_value', None) or self.lhs.output_field.get_db_prep_value
  181. return (
  182. '%s',
  183. [get_db_prep_value(v, connection, prepared=True) for v in value]
  184. if self.get_db_prep_lookup_value_is_iterable else
  185. [get_db_prep_value(value, connection, prepared=True)]
  186. )
  187. class FieldGetDbPrepValueIterableMixin(FieldGetDbPrepValueMixin):
  188. """
  189. Some lookups require Field.get_db_prep_value() to be called on each value
  190. in an iterable.
  191. """
  192. get_db_prep_lookup_value_is_iterable = True
  193. def get_prep_lookup(self):
  194. if hasattr(self.rhs, 'resolve_expression'):
  195. return self.rhs
  196. prepared_values = []
  197. for rhs_value in self.rhs:
  198. if hasattr(rhs_value, 'resolve_expression'):
  199. # An expression will be handled by the database but can coexist
  200. # alongside real values.
  201. pass
  202. elif self.prepare_rhs and hasattr(self.lhs.output_field, 'get_prep_value'):
  203. rhs_value = self.lhs.output_field.get_prep_value(rhs_value)
  204. prepared_values.append(rhs_value)
  205. return prepared_values
  206. def process_rhs(self, compiler, connection):
  207. if self.rhs_is_direct_value():
  208. # rhs should be an iterable of values. Use batch_process_rhs()
  209. # to prepare/transform those values.
  210. return self.batch_process_rhs(compiler, connection)
  211. else:
  212. return super().process_rhs(compiler, connection)
  213. def resolve_expression_parameter(self, compiler, connection, sql, param):
  214. params = [param]
  215. if hasattr(param, 'resolve_expression'):
  216. param = param.resolve_expression(compiler.query)
  217. if hasattr(param, 'as_sql'):
  218. sql, params = compiler.compile(param)
  219. return sql, params
  220. def batch_process_rhs(self, compiler, connection, rhs=None):
  221. pre_processed = super().batch_process_rhs(compiler, connection, rhs)
  222. # The params list may contain expressions which compile to a
  223. # sql/param pair. Zip them to get sql and param pairs that refer to the
  224. # same argument and attempt to replace them with the result of
  225. # compiling the param step.
  226. sql, params = zip(*(
  227. self.resolve_expression_parameter(compiler, connection, sql, param)
  228. for sql, param in zip(*pre_processed)
  229. ))
  230. params = itertools.chain.from_iterable(params)
  231. return sql, tuple(params)
  232. class PostgresOperatorLookup(FieldGetDbPrepValueMixin, Lookup):
  233. """Lookup defined by operators on PostgreSQL."""
  234. postgres_operator = None
  235. def as_postgresql(self, compiler, connection):
  236. lhs, lhs_params = self.process_lhs(compiler, connection)
  237. rhs, rhs_params = self.process_rhs(compiler, connection)
  238. params = tuple(lhs_params) + tuple(rhs_params)
  239. return '%s %s %s' % (lhs, self.postgres_operator, rhs), params
  240. @Field.register_lookup
  241. class Exact(FieldGetDbPrepValueMixin, BuiltinLookup):
  242. lookup_name = 'exact'
  243. def process_rhs(self, compiler, connection):
  244. from django.db.models.sql.query import Query
  245. if isinstance(self.rhs, Query):
  246. if self.rhs.has_limit_one():
  247. if not self.rhs.has_select_fields:
  248. self.rhs.clear_select_clause()
  249. self.rhs.add_fields(['pk'])
  250. else:
  251. raise ValueError(
  252. 'The QuerySet value for an exact lookup must be limited to '
  253. 'one result using slicing.'
  254. )
  255. return super().process_rhs(compiler, connection)
  256. def as_sql(self, compiler, connection):
  257. # Avoid comparison against direct rhs if lhs is a boolean value. That
  258. # turns "boolfield__exact=True" into "WHERE boolean_field" instead of
  259. # "WHERE boolean_field = True" when allowed.
  260. if (
  261. isinstance(self.rhs, bool) and
  262. getattr(self.lhs, 'conditional', False) and
  263. connection.ops.conditional_expression_supported_in_where_clause(self.lhs)
  264. ):
  265. lhs_sql, params = self.process_lhs(compiler, connection)
  266. template = '%s' if self.rhs else 'NOT %s'
  267. return template % lhs_sql, params
  268. return super().as_sql(compiler, connection)
  269. @Field.register_lookup
  270. class IExact(BuiltinLookup):
  271. lookup_name = 'iexact'
  272. prepare_rhs = False
  273. def process_rhs(self, qn, connection):
  274. rhs, params = super().process_rhs(qn, connection)
  275. if params:
  276. params[0] = connection.ops.prep_for_iexact_query(params[0])
  277. return rhs, params
  278. @Field.register_lookup
  279. class GreaterThan(FieldGetDbPrepValueMixin, BuiltinLookup):
  280. lookup_name = 'gt'
  281. @Field.register_lookup
  282. class GreaterThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup):
  283. lookup_name = 'gte'
  284. @Field.register_lookup
  285. class LessThan(FieldGetDbPrepValueMixin, BuiltinLookup):
  286. lookup_name = 'lt'
  287. @Field.register_lookup
  288. class LessThanOrEqual(FieldGetDbPrepValueMixin, BuiltinLookup):
  289. lookup_name = 'lte'
  290. class IntegerFieldFloatRounding:
  291. """
  292. Allow floats to work as query values for IntegerField. Without this, the
  293. decimal portion of the float would always be discarded.
  294. """
  295. def get_prep_lookup(self):
  296. if isinstance(self.rhs, float):
  297. self.rhs = math.ceil(self.rhs)
  298. return super().get_prep_lookup()
  299. @IntegerField.register_lookup
  300. class IntegerGreaterThanOrEqual(IntegerFieldFloatRounding, GreaterThanOrEqual):
  301. pass
  302. @IntegerField.register_lookup
  303. class IntegerLessThan(IntegerFieldFloatRounding, LessThan):
  304. pass
  305. @Field.register_lookup
  306. class In(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
  307. lookup_name = 'in'
  308. def process_rhs(self, compiler, connection):
  309. db_rhs = getattr(self.rhs, '_db', None)
  310. if db_rhs is not None and db_rhs != connection.alias:
  311. raise ValueError(
  312. "Subqueries aren't allowed across different databases. Force "
  313. "the inner query to be evaluated using `list(inner_query)`."
  314. )
  315. if self.rhs_is_direct_value():
  316. # Remove None from the list as NULL is never equal to anything.
  317. try:
  318. rhs = OrderedSet(self.rhs)
  319. rhs.discard(None)
  320. except TypeError: # Unhashable items in self.rhs
  321. rhs = [r for r in self.rhs if r is not None]
  322. if not rhs:
  323. raise EmptyResultSet
  324. # rhs should be an iterable; use batch_process_rhs() to
  325. # prepare/transform those values.
  326. sqls, sqls_params = self.batch_process_rhs(compiler, connection, rhs)
  327. placeholder = '(' + ', '.join(sqls) + ')'
  328. return (placeholder, sqls_params)
  329. else:
  330. if not getattr(self.rhs, 'has_select_fields', True):
  331. self.rhs.clear_select_clause()
  332. self.rhs.add_fields(['pk'])
  333. return super().process_rhs(compiler, connection)
  334. def get_rhs_op(self, connection, rhs):
  335. return 'IN %s' % rhs
  336. def as_sql(self, compiler, connection):
  337. max_in_list_size = connection.ops.max_in_list_size()
  338. if self.rhs_is_direct_value() and max_in_list_size and len(self.rhs) > max_in_list_size:
  339. return self.split_parameter_list_as_sql(compiler, connection)
  340. return super().as_sql(compiler, connection)
  341. def split_parameter_list_as_sql(self, compiler, connection):
  342. # This is a special case for databases which limit the number of
  343. # elements which can appear in an 'IN' clause.
  344. max_in_list_size = connection.ops.max_in_list_size()
  345. lhs, lhs_params = self.process_lhs(compiler, connection)
  346. rhs, rhs_params = self.batch_process_rhs(compiler, connection)
  347. in_clause_elements = ['(']
  348. params = []
  349. for offset in range(0, len(rhs_params), max_in_list_size):
  350. if offset > 0:
  351. in_clause_elements.append(' OR ')
  352. in_clause_elements.append('%s IN (' % lhs)
  353. params.extend(lhs_params)
  354. sqls = rhs[offset: offset + max_in_list_size]
  355. sqls_params = rhs_params[offset: offset + max_in_list_size]
  356. param_group = ', '.join(sqls)
  357. in_clause_elements.append(param_group)
  358. in_clause_elements.append(')')
  359. params.extend(sqls_params)
  360. in_clause_elements.append(')')
  361. return ''.join(in_clause_elements), params
  362. class PatternLookup(BuiltinLookup):
  363. param_pattern = '%%%s%%'
  364. prepare_rhs = False
  365. def get_rhs_op(self, connection, rhs):
  366. # Assume we are in startswith. We need to produce SQL like:
  367. # col LIKE %s, ['thevalue%']
  368. # For python values we can (and should) do that directly in Python,
  369. # but if the value is for example reference to other column, then
  370. # we need to add the % pattern match to the lookup by something like
  371. # col LIKE othercol || '%%'
  372. # So, for Python values we don't need any special pattern, but for
  373. # SQL reference values or SQL transformations we need the correct
  374. # pattern added.
  375. if hasattr(self.rhs, 'as_sql') or self.bilateral_transforms:
  376. pattern = connection.pattern_ops[self.lookup_name].format(connection.pattern_esc)
  377. return pattern.format(rhs)
  378. else:
  379. return super().get_rhs_op(connection, rhs)
  380. def process_rhs(self, qn, connection):
  381. rhs, params = super().process_rhs(qn, connection)
  382. if self.rhs_is_direct_value() and params and not self.bilateral_transforms:
  383. params[0] = self.param_pattern % connection.ops.prep_for_like_query(params[0])
  384. return rhs, params
  385. @Field.register_lookup
  386. class Contains(PatternLookup):
  387. lookup_name = 'contains'
  388. @Field.register_lookup
  389. class IContains(Contains):
  390. lookup_name = 'icontains'
  391. @Field.register_lookup
  392. class StartsWith(PatternLookup):
  393. lookup_name = 'startswith'
  394. param_pattern = '%s%%'
  395. @Field.register_lookup
  396. class IStartsWith(StartsWith):
  397. lookup_name = 'istartswith'
  398. @Field.register_lookup
  399. class EndsWith(PatternLookup):
  400. lookup_name = 'endswith'
  401. param_pattern = '%%%s'
  402. @Field.register_lookup
  403. class IEndsWith(EndsWith):
  404. lookup_name = 'iendswith'
  405. @Field.register_lookup
  406. class Range(FieldGetDbPrepValueIterableMixin, BuiltinLookup):
  407. lookup_name = 'range'
  408. def get_rhs_op(self, connection, rhs):
  409. return "BETWEEN %s AND %s" % (rhs[0], rhs[1])
  410. @Field.register_lookup
  411. class IsNull(BuiltinLookup):
  412. lookup_name = 'isnull'
  413. prepare_rhs = False
  414. def as_sql(self, compiler, connection):
  415. if not isinstance(self.rhs, bool):
  416. # When the deprecation ends, replace with:
  417. # raise ValueError(
  418. # 'The QuerySet value for an isnull lookup must be True or '
  419. # 'False.'
  420. # )
  421. warnings.warn(
  422. 'Using a non-boolean value for an isnull lookup is '
  423. 'deprecated, use True or False instead.',
  424. RemovedInDjango40Warning,
  425. )
  426. sql, params = compiler.compile(self.lhs)
  427. if self.rhs:
  428. return "%s IS NULL" % sql, params
  429. else:
  430. return "%s IS NOT NULL" % sql, params
  431. @Field.register_lookup
  432. class Regex(BuiltinLookup):
  433. lookup_name = 'regex'
  434. prepare_rhs = False
  435. def as_sql(self, compiler, connection):
  436. if self.lookup_name in connection.operators:
  437. return super().as_sql(compiler, connection)
  438. else:
  439. lhs, lhs_params = self.process_lhs(compiler, connection)
  440. rhs, rhs_params = self.process_rhs(compiler, connection)
  441. sql_template = connection.ops.regex_lookup(self.lookup_name)
  442. return sql_template % (lhs, rhs), lhs_params + rhs_params
  443. @Field.register_lookup
  444. class IRegex(Regex):
  445. lookup_name = 'iregex'
  446. class YearLookup(Lookup):
  447. def year_lookup_bounds(self, connection, year):
  448. output_field = self.lhs.lhs.output_field
  449. if isinstance(output_field, DateTimeField):
  450. bounds = connection.ops.year_lookup_bounds_for_datetime_field(year)
  451. else:
  452. bounds = connection.ops.year_lookup_bounds_for_date_field(year)
  453. return bounds
  454. def as_sql(self, compiler, connection):
  455. # Avoid the extract operation if the rhs is a direct value to allow
  456. # indexes to be used.
  457. if self.rhs_is_direct_value():
  458. # Skip the extract part by directly using the originating field,
  459. # that is self.lhs.lhs.
  460. lhs_sql, params = self.process_lhs(compiler, connection, self.lhs.lhs)
  461. rhs_sql, _ = self.process_rhs(compiler, connection)
  462. rhs_sql = self.get_direct_rhs_sql(connection, rhs_sql)
  463. start, finish = self.year_lookup_bounds(connection, self.rhs)
  464. params.extend(self.get_bound_params(start, finish))
  465. return '%s %s' % (lhs_sql, rhs_sql), params
  466. return super().as_sql(compiler, connection)
  467. def get_direct_rhs_sql(self, connection, rhs):
  468. return connection.operators[self.lookup_name] % rhs
  469. def get_bound_params(self, start, finish):
  470. raise NotImplementedError(
  471. 'subclasses of YearLookup must provide a get_bound_params() method'
  472. )
  473. class YearExact(YearLookup, Exact):
  474. def get_direct_rhs_sql(self, connection, rhs):
  475. return 'BETWEEN %s AND %s'
  476. def get_bound_params(self, start, finish):
  477. return (start, finish)
  478. class YearGt(YearLookup, GreaterThan):
  479. def get_bound_params(self, start, finish):
  480. return (finish,)
  481. class YearGte(YearLookup, GreaterThanOrEqual):
  482. def get_bound_params(self, start, finish):
  483. return (start,)
  484. class YearLt(YearLookup, LessThan):
  485. def get_bound_params(self, start, finish):
  486. return (start,)
  487. class YearLte(YearLookup, LessThanOrEqual):
  488. def get_bound_params(self, start, finish):
  489. return (finish,)
  490. class UUIDTextMixin:
  491. """
  492. Strip hyphens from a value when filtering a UUIDField on backends without
  493. a native datatype for UUID.
  494. """
  495. def process_rhs(self, qn, connection):
  496. if not connection.features.has_native_uuid_field:
  497. from django.db.models.functions import Replace
  498. if self.rhs_is_direct_value():
  499. self.rhs = Value(self.rhs)
  500. self.rhs = Replace(self.rhs, Value('-'), Value(''), output_field=CharField())
  501. rhs, params = super().process_rhs(qn, connection)
  502. return rhs, params
  503. @UUIDField.register_lookup
  504. class UUIDIExact(UUIDTextMixin, IExact):
  505. pass
  506. @UUIDField.register_lookup
  507. class UUIDContains(UUIDTextMixin, Contains):
  508. pass
  509. @UUIDField.register_lookup
  510. class UUIDIContains(UUIDTextMixin, IContains):
  511. pass
  512. @UUIDField.register_lookup
  513. class UUIDStartsWith(UUIDTextMixin, StartsWith):
  514. pass
  515. @UUIDField.register_lookup
  516. class UUIDIStartsWith(UUIDTextMixin, IStartsWith):
  517. pass
  518. @UUIDField.register_lookup
  519. class UUIDEndsWith(UUIDTextMixin, EndsWith):
  520. pass
  521. @UUIDField.register_lookup
  522. class UUIDIEndsWith(UUIDTextMixin, IEndsWith):
  523. pass