New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fixed #28117 -- Added a helpful message in loaddata when psycopg2 can't load a fixture due to NUL(0x00) characters. #9500
Conversation
A test is also required. |
@timgraham done |
@@ -0,0 +1,34 @@ | |||
[ | |||
{ | |||
"pk": 1, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need 4 objects in the fixture rather than 1?
tests/fixtures/tests.py
Outdated
Category.objects.all().delete() | ||
Site.objects.all().delete() | ||
# Load Postgres fixture | ||
with self.assertRaises(ValueError) as cm: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
use assertRaisesMessage()
.
tests/fixtures/tests.py
Outdated
# Load Postgres fixture | ||
with self.assertRaises(ValueError) as cm: | ||
management.call_command('loaddata', 'postgres_nul.json', verbosity=0) | ||
self.assertIn('A string literal cannot contain NUL (0x00) characters.', cm.exception.args[0]) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should also include the "Could not load .." part of the error message -- otherwise the test passes without the change.
tests/fixtures/tests.py
Outdated
@@ -778,3 +778,17 @@ def test_format_discovery(self): | |||
'<Article: Time to reform copyright>', | |||
'<Article: Poker has no place on ESPN>', | |||
]) | |||
|
|||
|
|||
class PostgresNulLoadingTests(TestCase): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think a separate test class isn't needed. I'd put the test below test_loaddata_error_message
.
tests/fixtures/tests.py
Outdated
|
||
@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific") | ||
def test_loading_nul_0x00_chars(self): | ||
apps.clear_cache() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are these clear/delete lines needed or did you copy them from the other test?
@@ -0,0 +1,34 @@ | |||
[ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
file name: null_character_in_field_value.json
@@ -180,7 +180,9 @@ def load_label(self, fixture_label): | |||
'\rProcessed %i object(s).' % loaded_objects_in_fixture, | |||
ending='' | |||
) | |||
except (DatabaseError, IntegrityError) as e: | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Remove blank line.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
# psycopg2 raises ValueError if a field contains NUL characters (0x00).
@timgraham Done |
…'t load a fixture due to NUL characters.
@srinivasreddy Thank you for fixing this issue, and thanks to all involved. |
https://code.djangoproject.com/ticket/28117