#30238: Exception when saving model created with string for DateField
     Reporter:  Mitchell Harvey      |                    Owner:  nobody
         Type:  Bug                  |                   Status:  closed
    Component:  Database layer       |                  Version:  2.1
  (models, ORM)                      |
     Severity:  Normal               |               Resolution:  invalid
     Keywords:                       |             Triage Stage:
                                     |  Unreviewed
    Has patch:  0                    |      Needs documentation:  0
  Needs tests:  0                    |  Patch needs improvement:  0
Easy pickings:  1                    |                    UI/UX:  0
Changes (by Carlton Gibson):

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


 The `AttributeError` is not raised. This test fails as the
 `assertRaisesMessage()` call:

 class Tests(TestCase):

     def test_attribute_error_stops_save(self):

         my_model_args = { 'worthless_field' : '2019-02-07'}
         myExceptionalModel = MyModel( **my_model_args)

         msg = "'str' object has no attribute 'isoformat'"
         with self.assertRaisesMessage(AttributeError, msg):

         self.assertEqual(0, MyModel.objects.count())

 Behaviour is as expected:

 >>> myExceptionalModel.save()
 >>> myExceptionalModel.refresh_from_db()
 >>> myExceptionalModel.worthless_field
 datetime.date(2019, 2, 7)

 Sample app with model and test case attached.

Ticket URL: <https://code.djangoproject.com/ticket/30238#comment:1>
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 django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
For more options, visit https://groups.google.com/d/optout.

Reply via email to