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)
| 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): |
no test coverage detected