| 485 | | |
|---|
| 486 | | # If you're not careful, it's possible to introduce infinite loops via default |
|---|
| 487 | | # ordering on foreign keys in a cycle. We detect that. |
|---|
| 488 | | >>> LoopX.objects.all() |
|---|
| 489 | | Traceback (most recent call last): |
|---|
| 490 | | ... |
|---|
| 491 | | FieldError: Infinite loop caused by ordering. |
|---|
| 492 | | |
|---|
| 493 | | >>> LoopZ.objects.all() |
|---|
| 494 | | Traceback (most recent call last): |
|---|
| 495 | | ... |
|---|
| 496 | | FieldError: Infinite loop caused by ordering. |
|---|
| 497 | | |
|---|
| 498 | | # ... but you can still order in a non-recursive fashion amongst linked fields |
|---|
| 499 | | # (the previous test failed because the default ordering was recursive). |
|---|
| 500 | | >>> LoopX.objects.all().order_by('y__x__y__x__id') |
|---|
| 501 | | [] |
|---|
| | 827 | # In Python 2.3, exceptions raised in __len__ are swallowed (Python issue |
|---|
| | 828 | # 1242657), so these cases return an empty list, rather than raising an |
|---|
| | 829 | # exception. Not a lot we can do about that, unfortunately, due to the way |
|---|
| | 830 | # Python handles list() calls internally. Thus, we skip the tests for Python |
|---|
| | 831 | # 2.3. |
|---|
| | 832 | if sys.version_info >= (2, 4): |
|---|
| | 833 | __test__["API_TESTS"] += """ |
|---|
| | 834 | # If you're not careful, it's possible to introduce infinite loops via default |
|---|
| | 835 | # ordering on foreign keys in a cycle. We detect that. |
|---|
| | 836 | >>> LoopX.objects.all() |
|---|
| | 837 | Traceback (most recent call last): |
|---|
| | 838 | ... |
|---|
| | 839 | FieldError: Infinite loop caused by ordering. |
|---|
| | 840 | |
|---|
| | 841 | >>> LoopZ.objects.all() |
|---|
| | 842 | Traceback (most recent call last): |
|---|
| | 843 | ... |
|---|
| | 844 | FieldError: Infinite loop caused by ordering. |
|---|
| | 845 | |
|---|
| | 846 | # ... but you can still order in a non-recursive fashion amongst linked fields |
|---|
| | 847 | # (the previous test failed because the default ordering was recursive). |
|---|
| | 848 | >>> LoopX.objects.all().order_by('y__x__y__x__id') |
|---|
| | 849 | [] |
|---|
| | 850 | """ |
|---|