mirror of
https://github.com/django/django.git
synced 2024-12-22 17:16:24 +00:00
Fixed #28117 -- Added a helpful message in loaddata when psycopg2 can't load a fixture due to NUL characters.
This commit is contained in:
parent
51a00749e9
commit
58ec55b157
@ -180,7 +180,8 @@ class Command(BaseCommand):
|
||||
'\rProcessed %i object(s).' % loaded_objects_in_fixture,
|
||||
ending=''
|
||||
)
|
||||
except (DatabaseError, IntegrityError) as e:
|
||||
# psycopg2 raises ValueError if data contains NUL chars.
|
||||
except (DatabaseError, IntegrityError, ValueError) as e:
|
||||
e.args = ("Could not load %(app_label)s.%(object_name)s(pk=%(pk)s): %(error_msg)s" % {
|
||||
'app_label': obj.object._meta.app_label,
|
||||
'object_name': obj.object._meta.object_name,
|
||||
|
10
tests/fixtures/fixtures/null_character_in_field_value.json
vendored
Normal file
10
tests/fixtures/fixtures/null_character_in_field_value.json
vendored
Normal file
@ -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"
|
||||
}
|
||||
}
|
||||
]
|
9
tests/fixtures/tests.py
vendored
9
tests/fixtures/tests.py
vendored
@ -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")
|
||||
|
Loading…
Reference in New Issue
Block a user