我们从Python开源项目中,提取了以下4个代码示例,用于说明如何使用django.db.utils.DataError()。
def populate_from_bibtex(self, bibtex_dict): for key in bibtex_dict.keys(): if key not in ['ID', 'date']: setattr(self, key, bibtex_dict[key]) try: self.save() except DataError as e: print(e, bibtex_dict)
def handle_listing(listing_object, results_item): try: new_listing_object = extract_listing_data(results_item) updated_listing_object = update_core_listing_data(listing_object, new_listing_object) updated_listing_object.save() except (ValueError, DataError, PG_DataError): logger.debug(traceback.print_exc(limit=None)) raise ListingException() # Handle premature exits
def test_message_short_enough(self): """ Test that a message length can't be superior to 140 characters """ t = Tweet( time = 60, message = 't'*141 ) # assertRaises doesn't seem to work try: t.save() except Exception as e: self.assertTrue(type(e) is DataError)
def test_array_int_raises(self): self.assertRaises(DataError, self.queryset.update, prices=ArrayAppend('prices', 'test'))