From 58ec55b157b3c4cc9dc0a944804f8a719ff4e12f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Srinivas=20Reddy=20Thatiparthy=20=28=E0=B0=B6=E0=B1=8D?= =?UTF-8?q?=E0=B0=B0=E0=B1=80=E0=B0=A8=E0=B0=BF=E0=B0=B5=E0=B0=BE=E0=B0=B8?= =?UTF-8?q?=E0=B1=8D=20=E0=B0=B0=E0=B1=86=E0=B0=A1=E0=B1=8D=E0=B0=A1?= =?UTF-8?q?=E0=B0=BF=20=E0=B0=A4=E0=B0=BE=E0=B0=9F=E0=B0=BF=E0=B0=AA?= =?UTF-8?q?=E0=B0=B0=E0=B1=8D=E0=B0=A4=E0=B0=BF=29?= Date: Sat, 30 Dec 2017 22:46:11 +0530 Subject: Fixed #28117 -- Added a helpful message in loaddata when psycopg2 can't load a fixture due to NUL characters. --- tests/fixtures/fixtures/null_character_in_field_value.json | 10 ++++++++++ tests/fixtures/tests.py | 9 +++++++++ 2 files changed, 19 insertions(+) create mode 100644 tests/fixtures/fixtures/null_character_in_field_value.json (limited to 'tests/fixtures') diff --git a/tests/fixtures/fixtures/null_character_in_field_value.json b/tests/fixtures/fixtures/null_character_in_field_value.json new file mode 100644 index 0000000000..7b246a0544 --- /dev/null +++ b/tests/fixtures/fixtures/null_character_in_field_value.json @@ -0,0 +1,10 @@ +[ + { + "pk": "2", + "model": "fixtures.article", + "fields": { + "headline": "Poker has no place on ESPN\u0000", + "pub_date": "2006-06-16 12:00:00" + } + } +] diff --git a/tests/fixtures/tests.py b/tests/fixtures/tests.py index 477f64ce05..4bdaeefbb0 100644 --- a/tests/fixtures/tests.py +++ b/tests/fixtures/tests.py @@ -571,6 +571,15 @@ class FixtureLoadingTests(DumpDataAssertMixin, TestCase): management.call_command('loaddata', 'invalid.json', verbosity=0) self.assertIn("Could not load fixtures.Article(pk=1):", cm.exception.args[0]) + @unittest.skipUnless(connection.vendor == 'postgresql', 'psycopg2 prohibits null characters in data.') + def test_loaddata_null_characters_on_postgresql(self): + msg = ( + 'Could not load fixtures.Article(pk=2): ' + 'A string literal cannot contain NUL (0x00) characters.' + ) + with self.assertRaisesMessage(ValueError, msg): + management.call_command('loaddata', 'null_character_in_field_value.json') + def test_loaddata_app_option(self): with self.assertRaisesMessage(CommandError, "No fixture named 'db_fixture_1' found."): management.call_command('loaddata', 'db_fixture_1', verbosity=0, app_label="someotherapp") -- cgit v1.2.1