Commit 2413623
committed
fail-on-template-vars: improve compatibility with Django behavior
With `OneToOneField`, Django raises `Model.DoesNotExist` which is
converted by its template engine to `string_if_invalid`:
https://github.com/django/django/blob/5.0.7/django/template/base.py#L932-L933
It is usually falsy, hence the need for `InvalidVarException.__bool__`
to return `bool(self.origin_value)` to be consistent with Django's
default behavior.
However to trigger `InvalidVarException` behavior and its dreaded
`InvalidVarException.__mod__`, it needs to go through this check:
https://github.com/django/django/blob/5.0.7/django/template/base.py#L716
and thus also needs to be truthy hence the stack inspecting `__bool__`
method to know what to return.1 parent 3c46471 commit 2413623
2 files changed
+51
-0
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
688 | 688 | | |
689 | 689 | | |
690 | 690 | | |
| 691 | + | |
| 692 | + | |
| 693 | + | |
| 694 | + | |
| 695 | + | |
| 696 | + | |
| 697 | + | |
691 | 698 | | |
692 | 699 | | |
693 | 700 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
188 | 188 | | |
189 | 189 | | |
190 | 190 | | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
| 194 | + | |
| 195 | + | |
| 196 | + | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
| 204 | + | |
| 205 | + | |
| 206 | + | |
| 207 | + | |
| 208 | + | |
| 209 | + | |
| 210 | + | |
| 211 | + | |
| 212 | + | |
| 213 | + | |
| 214 | + | |
| 215 | + | |
| 216 | + | |
| 217 | + | |
| 218 | + | |
| 219 | + | |
| 220 | + | |
| 221 | + | |
| 222 | + | |
| 223 | + | |
| 224 | + | |
| 225 | + | |
| 226 | + | |
| 227 | + | |
| 228 | + | |
| 229 | + | |
| 230 | + | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
191 | 235 | | |
192 | 236 | | |
193 | 237 | | |
| |||
0 commit comments