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

Editing a book results in apparent error despite the edit succeeding #83

Open
adborden opened this issue Feb 16, 2017 · 1 comment
Open
Labels

Comments

@adborden
Copy link
Member

After editing a book, the user is returned to the edit page, but a message is displayed "The book already exists in the server." This is confusing because it implies the edit was not possible, but the edit in fact was successful.

Repro

  1. Login
  2. View book detail
  3. Click "edit"
  4. Change the book title field
  5. Click "edit" to submit

Expected
User is redirected to the book detail page.

Actual
Error "The book already exists in the server." appears.

screenshot from 2017-02-16 07-24-32

@adborden adborden added the Bug label Feb 16, 2017
@murlock
Copy link
Contributor

murlock commented May 17, 2017

I've looking for this issue and I've found that validate_unique doesn't check if sha256 refers to current object or not.

I've made a small fix but there are others issues later in forms.py...

     def validate_unique(self, *args, **kwargs):
         if not self.file_sha256sum:
             self.file_sha256sum = sha256_sum(self.book_file)
-        if (self.__class__.objects.filter(
-                file_sha256sum=self.file_sha256sum).exists()):
+        unicity = self.__class__.objects.filter(file_sha256sum=self.file_sha256sum)
+        if self.pk is not None:
+            unicity = unicity.exclude(pk=self.pk)
+        if (unicity.exists()):
             raise ValidationError({
                 NON_FIELD_ERRORS:['The book already exists in the server.',]})

This fix requires testing but I saw that you have began upgrading this project to Django 1.11, I'll be happy to help with adding test.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants