'select_on_save works correctly if the database doesn\'t return correct
information about matched rows from UPDATE.'

def test_select_on_save_lying_update(self):

    orig_class = Article._base_manager._queryset_class
    class FakeQuerySet(QuerySet, ):
        called = False
        def _update(self, *args, **kwargs):
            FakeQuerySet.called = True
            super()._update(*args, **kwargs)
            return 0
    try:
        Article._base_manager._queryset_class = FakeQuerySet
        asos = ArticleSelectOnSave.objects.create(pub_date=datetime.now())
        with self.assertNumQueries(3):
            asos.save()
            self.assertTrue(FakeQuerySet.called)
        with self.assertRaisesMessage(DatabaseError, 'Forced    update    did    not    affect    any    rows.'):
            asos.save(force_update=True)
        msg = "An    error    occurred    in    the    current    transaction.    You    can't    execute    queries    until    the    end    of    the    'atomic'    block."
        with self.assertRaisesMessage(DatabaseError, msg):
            asos.save(update_fields=['pub_date'])
    finally:
        Article._base_manager._queryset_class = orig_class
