MCPcopy
hub / github.com/django/django / _resolve_output_field

Method _resolve_output_field

django/db/models/expressions.py:346–374  ·  view source on GitHub ↗

Attempt to infer the output type of the expression. As a guess, if the output fields of all source fields match then simply infer the same type here. If a source's output field resolves to None, exclude it from this check. If all sources are None, then an e

(self)

Source from the content-addressed store, hash-verified

344 return
345
346 def _resolve_output_field(self):
347 """
348 Attempt to infer the output type of the expression.
349
350 As a guess, if the output fields of all source fields match then simply
351 infer the same type here.
352
353 If a source's output field resolves to None, exclude it from this
354 check. If all sources are None, then an error is raised higher up the
355 stack in the output_field property.
356 """
357 # This guess is mostly a bad idea, but there is quite a lot of code
358 # (especially 3rd party Func subclasses) that depend on it, we'd need a
359 # deprecation path to fix it.
360 sources_iter = (
361 source for source in self.get_source_fields() if source is not None
362 )
363 for output_field in sources_iter:
364 for source in sources_iter:
365 if not isinstance(output_field, source.__class__):
366 raise FieldError(
367 "Expression contains mixed types: %s, %s. You must "
368 "set output_field."
369 % (
370 output_field.__class__.__name__,
371 source.__class__.__name__,
372 )
373 )
374 return output_field
375
376 @staticmethod
377 def _convert_value_noop(value, expression, connection):

Callers 1

output_fieldMethod · 0.95

Calls 2

get_source_fieldsMethod · 0.95
FieldErrorClass · 0.90

Tested by

no test coverage detected