Skip to content
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

Merged
merged 1 commit into from Dec 30, 2017

Conversation

srinivasreddy
Copy link
Contributor

@timgraham
Copy link
Member

A test is also required.

@srinivasreddy
Copy link
Contributor Author

@timgraham done

@timgraham timgraham changed the title Fixes#28117: ValueError will be raised when an object contains NUL(0x00) chars on Postrgres DB Fixed #28117 -- Added a helpful message in loaddata when psycopg2 can't load a fixture due to NUL(0x00) characters. Dec 29, 2017
@@ -0,0 +1,34 @@
[
{
"pk": 1,
Copy link
Member

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?

Category.objects.all().delete()
Site.objects.all().delete()
# Load Postgres fixture
with self.assertRaises(ValueError) as cm:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assertRaisesMessage().

# 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])
Copy link
Member

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.

@@ -778,3 +778,17 @@ def test_format_discovery(self):
'<Article: Time to reform copyright>',
'<Article: Poker has no place on ESPN>',
])


class PostgresNulLoadingTests(TestCase):
Copy link
Member

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.


@unittest.skipUnless(connection.vendor == 'postgresql', "PostgreSQL specific")
def test_loading_nul_0x00_chars(self):
apps.clear_cache()
Copy link
Member

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 @@
[
Copy link
Member

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:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove blank line.

Copy link
Member

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).

@srinivasreddy
Copy link
Contributor Author

@timgraham Done

@nkuttler
Copy link

@srinivasreddy Thank you for fixing this issue, and thanks to all involved.

@timgraham timgraham merged commit 58ec55b into django:master Dec 30, 2017
@srinivasreddy srinivasreddy deleted the 28117 branch December 30, 2017 18:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants