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 #28950 -- Fixed ArrayField.has_changed() for empty values. #9520

Merged
merged 2 commits into from
Apr 7, 2018
Merged

Fixed #28950 -- Fixed ArrayField.has_changed() for empty values. #9520

merged 2 commits into from
Apr 7, 2018

Conversation

vinayinvicible
Copy link
Contributor

@@ -737,6 +737,14 @@ def test_already_converted_value(self):
vals = ['a', 'b', 'c']
self.assertEqual(field.clean(vals), vals)

def test_has_changed(self):
field = SimpleArrayField(forms.CharField())
self.assertFalse(field.has_changed(None, None))
Copy link
Member

Choose a reason for hiding this comment

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

use self.assertIs(..., False) (assertFalse checks bool(val) is False)

field = SimpleArrayField(forms.CharField())
self.assertFalse(field.has_changed(None, None))
self.assertFalse(field.has_changed(None, ''))
self.assertFalse(field.has_changed(None, []))
Copy link
Member

Choose a reason for hiding this comment

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

Are [], None, and '' all realistic values for data? Generally I would expect only string values from POST data.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

for an empty field '' is passed in POST data.
if you are referring to pure html form implementation, then None and [] are not encountered. but if the form is used otherwise (validating api requests) you might expect to see these values.

try:
data_value = self.to_python(data)
except ValidationError:
pass
Copy link
Member

Choose a reason for hiding this comment

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

Test coverage is missing for this branch. You might need to add some initial test coverage for has_changed() in a separate commit.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

added testcase for existing implementation

@timgraham timgraham changed the title Fixed #28950 -- Made Arrayfield.has_changed compare empty values properly Fixed #28950 -- Fixed ArrayField.has_changed() for empty values. Apr 7, 2018
@timgraham timgraham merged commit 6a1957b into django:master Apr 7, 2018
@vinayinvicible vinayinvicible deleted the ticket_28950 branch January 25, 2019 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants