Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Fixed #18709 -- Check if initial_value is a callable #246

merged 1 commit into from

4 participants

Jeroen Dekkers Florian Apolloner Kamil Gałuszka Marc Tamlyn
Jeroen Dekkers

In _get_changed_data, check if initial_value is a callable and call it
if it is.

Florian Apolloner

Could it be that you got the ticket number wrong?

Jeroen Dekkers

You're right, I just fixed the number. Somehow I wrote the wrong number in the commit message and didn't notice when doing the pull request. It should be 18709 as the branch name said.

Kamil Gałuszka

It will be great to merge that.

Jeroen Dekkers dekkers Fixed #18709 -- Check if initial_value is a callable
In _get_changed_data, check if initial_value is a callable and call it
if it is.
Jeroen Dekkers

I rebased to current master

Marc Tamlyn

Looks good to me.

Marc Tamlyn mjtamlyn merged commit adeec00 into from
Jeroen Dekkers dekkers deleted the branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 21, 2013
  1. Jeroen Dekkers

    Fixed #18709 -- Check if initial_value is a callable

    dekkers authored
    In _get_changed_data, check if initial_value is a callable and call it
    if it is.
This page is out of date. Refresh to see the latest.
Showing with 25 additions and 1 deletion.
  1. +2 −0  django/forms/
  2. +23 −1 tests/forms_tests/tests/
2  django/forms/
@@ -342,6 +342,8 @@ def changed_data(self):
data_value = field.widget.value_from_datadict(, self.files, prefixed_name)
if not field.show_hidden_initial:
initial_value = self.initial.get(name, field.initial)
+ if callable(initial_value):
+ initial_value = initial_value()
initial_prefixed_name = self.add_initial_prefix(name)
hidden_widget = field.hidden_widget()
24 tests/forms_tests/tests/
@@ -1,8 +1,10 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
+import datetime
from django.forms import (CharField, DateField, FileField, Form, IntegerField,
- ValidationError, formsets)
+ SplitDateTimeField, ValidationError, formsets)
from django.forms.formsets import BaseFormSet, formset_factory
from django.forms.util import ErrorList
from django.test import TestCase
@@ -45,6 +47,13 @@ def clean(self):
formset=BaseFavoriteDrinksFormSet, extra=3)
+# Used in ``test_formset_splitdatetimefield``.
+class SplitDateTimeForm(Form):
+ when = SplitDateTimeField(
+SplitDateTimeFormSet = formset_factory(SplitDateTimeForm)
class FormsFormsetTestCase(TestCase):
def test_basic_formset(self):
# A FormSet constructor takes the same arguments as Form. Let's create a FormSet
@@ -882,6 +891,19 @@ def test_formset_nonzero(self):
self.assertEqual(len(formset.forms), 0)
+ def test_formset_splitdatetimefield(self):
+ """
+ Formset should also work with SplitDateTimeField(
+ Regression test for #18709.
+ """
+ data = {
+ 'form-TOTAL_FORMS': '1',
+ 'form-INITIAL_FORMS': '0',
+ 'form-0-when_0': '1904-06-16',
+ 'form-0-when_1': '15:51:33',
+ }
+ formset = SplitDateTimeFormSet(data)
+ self.assertTrue(formset.is_valid())
def test_formset_error_class(self):
# Regression tests for #16479 -- formsets form use ErrorList instead of supplied error_class
Something went wrong with that request. Please try again.