| 501 | return sql, params |
| 502 | |
| 503 | def get_expression_for_validation(self): |
| 504 | # Ignore expressions that cannot be used during a constraint |
| 505 | # validation. |
| 506 | if not getattr(self, "constraint_validation_compatible", True): |
| 507 | try: |
| 508 | (expression,) = self.get_source_expressions() |
| 509 | except ValueError as e: |
| 510 | raise ValueError( |
| 511 | "Expressions with constraint_validation_compatible set to False " |
| 512 | "must have only one source expression." |
| 513 | ) from e |
| 514 | else: |
| 515 | return expression |
| 516 | return self |
| 517 | |
| 518 | |
| 519 | @deconstructible |