#25233: Unable save model in admin with HStoreField field after manually saving
invalid data
----------------------------------+--------------------------------------
     Reporter:  hongphi           |                    Owner:
         Type:  Bug               |                   Status:  new
    Component:  contrib.postgres  |                  Version:  1.8
     Severity:  Normal            |               Resolution:
     Keywords:                    |             Triage Stage:  Unreviewed
    Has patch:  0                 |      Needs documentation:  0
  Needs tests:  0                 |  Patch needs improvement:  0
Easy pickings:  0                 |                    UI/UX:  0
----------------------------------+--------------------------------------
Changes (by mcastle):

 * status:  closed => new
 * resolution:  invalid =>


Comment:

 I see this same error in the Admin even when entering valid data with
 double quotes, using Django 1.8.3 and Python 2.7.10:
 {{{
 patient = Patient.objects.create(user=user, gender="male",
 mobile_telecom="555-555-4456",
 emergency_contacts={"urgent_care":"555-555-5555"}, utc_offset=0,
 birthdate=datetime.datetime.now())
 }}}

 Returning emergency_contacts from the shell results in single quoted data:
 {{{
 In [21]: patient.emergency_contacts
 Out[21]: {'urgent_care': '6467702435'}
 }}}

 From the traceback, it seems django's changed_data in forms.py is
 transforming the double-quoted data to single-quoted data:

 {{{
 /lib/python2.7/site-packages/django/forms/forms.py in changed_data

                         try:

                             initial_value =
 field.to_python(hidden_widget.value_from_datadict(

                                 self.data, self.files,
 initial_prefixed_name))

                         except ValidationError:

                             # Always assume data has changed if validation
 fails.

                             self._changed_data.append(name)

                             continue

                                 if field.has_changed(initial_value,
 data_value):

      ...

                         self._changed_data.append(name)

             return self._changed_data

         @property

         def media(self):

             """

 ▼ Local vars
 Variable        Value
 data_value

 u'{"urgent_care": "555-555-5555"}'

 name

 'emergency_contacts'

 initial_value

 {u'urgent_care': u'555-555-5555'}

 self

 <PatientForm bound=True, valid=True,
 
fields=(user;gender;birthdate;mobile_telecom;emergency_contacts;utc_offset;hipaa_authorization_timestamp)>

 field

 <django.contrib.postgres.forms.hstore.HStoreField object at 0x105d54450>

 prefixed_name

 'emergency_contacts'
 }}}


 This is using the following model:

 {{{
 class Patient(TimeStampedModel):
     id = models.UUIDField(primary_key=True, default=uuid.uuid4,
 editable=False)
     user = models.OneToOneField(settings.AUTH_USER_MODEL)
     gender = models.CharField(max_length=10, choices=GENDER_CHOICES)
     birthdate = models.DateField()
     mobile_telecom = PhoneNumberField(unique=True)
     emergency_contacts = HStoreField(default={"urgent_care": ""})
     utc_offset = models.IntegerField(default=0)
     hipaa_authorization_timestamp = models.DateTimeField(null=True,
 blank=True)
 }}}

--
Ticket URL: <https://code.djangoproject.com/ticket/25233#comment:3>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/065.a800ed2ca6bd935ea09e94b25c5c55a4%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to