Skip to content

Fix setting fields to null using bulk_update #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion testapp/tests/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
from django.db.models.expressions import Case, Exists, OuterRef, Subquery, Value, When
from django.test import TestCase

from ..models import Author, Comment, Post
from ..models import Author, Comment, Editor, Post

DJANGO3 = VERSION[0] >= 3

Expand All @@ -22,6 +22,18 @@ def test_with_count(self):
).filter(post_exists=True).count()


class TestBulkUpdate(TestCase):
def test_set_null(self):
author = Author.objects.create(name="author")
editor = Editor.objects.create(name="editor")

posts = [
Post.objects.create(title="foo", author=author, alt_editor=editor),
]
posts[0].alt_editor = None
Post.objects.bulk_update(posts, ['alt_editor'])


class TestExists(TestCase):
def setUp(self):
self.author = Author.objects.create(name="author")
Expand Down