diff options
| author | Josh Smeaton <josh.smeaton@gmail.com> | 2015-01-07 21:30:25 +1100 |
|---|---|---|
| committer | Tim Graham <timograham@gmail.com> | 2015-01-07 19:07:49 -0500 |
| commit | 8713ea7568af8871bf1306f14cc928058df0d4c7 (patch) | |
| tree | bf85b55ee5aeb25c0571f9fb54d380b94724f328 /tests | |
| parent | 1f03d2d924ba90e83dc9d8c93438bf5ee2f17ccd (diff) | |
Fixed null handling in Value expression
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/annotations/tests.py | 7 | ||||
| -rw-r--r-- | tests/expressions/tests.py | 15 |
2 files changed, 21 insertions, 1 deletions
diff --git a/tests/annotations/tests.py b/tests/annotations/tests.py index 570ef4d52c..90a9c13048 100644 --- a/tests/annotations/tests.py +++ b/tests/annotations/tests.py @@ -190,6 +190,13 @@ class NonAggregateAnnotationTestCase(TestCase): lambda d: (d.other_name, d.other_chain, d.is_open, d.book_isbn) ) + def test_null_annotation(self): + """ + Test that annotating None onto a model round-trips + """ + book = Book.objects.annotate(no_value=Value(None, output_field=IntegerField())).first() + self.assertIsNone(book.no_value) + def test_column_field_ordering(self): """ Test that columns are aligned in the correct order for diff --git a/tests/expressions/tests.py b/tests/expressions/tests.py index 0e9bd57e91..8165a496dc 100644 --- a/tests/expressions/tests.py +++ b/tests/expressions/tests.py @@ -5,7 +5,7 @@ import datetime from django.core.exceptions import FieldError from django.db import connection, transaction, DatabaseError -from django.db.models import F +from django.db.models import F, Value from django.test import TestCase, skipIfDBFeature, skipUnlessDBFeature from django.test.utils import Approximate from django.utils import six @@ -174,6 +174,19 @@ class BasicExpressionsTests(TestCase): ordered=False ) + def test_update_with_none(self): + Number.objects.create(integer=1, float=1.0) + Number.objects.create(integer=2) + Number.objects.filter(float__isnull=False).update(float=Value(None)) + self.assertQuerysetEqual( + Number.objects.all(), [ + None, + None, + ], + lambda n: n.float, + ordered=False + ) + def test_filter_with_join(self): # F Expressions can also span joins Company.objects.update(point_of_contact=F('ceo')) |
