Django

Code

Ticket #1511 (closed: fixed)

Opened 3 years ago

Last modified 2 months ago

[patch] History always records changes to boolean fields

Reported by: vitaliyf Assigned to: nobody
Milestone: Component: django.contrib.admin
Version: SVN Keywords:
Cc: cmlenz@gmx.de, brian@iomnis.com Triage Stage: Accepted
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

Description

I have a model with a "flagfield = models.BooleanField?(default=False)" field. I am using a plain vanilla admin to edit it, with data stored in a MySQL 5.0.x database.

The admin works fine and all fields are updated properly. However, it looks like "Changed flagfield." entries are added to history even if the value (checkbox) was not changed.

I know very little (read: nothing) about Django internals, but it appears that there is some inconsistency with boolean fields - sometimes they are numeric (0/1) and sometimes they are True/False. db/models/manipulators.py line 113 does the comparison and I see it comparing str(1) with str(True) which fails and thus adds the field to change history.

Quite possibly there are other side-effects from this besides history.

Attachments

manipulators-bool-changed.diff (1.0 kB) - added by dummy@habmalnefrage.de on 08/02/06 16:27:49.
solution: don't check str()-values, check real values instead
django_1511.diff (1.1 kB) - added by Christopher Lenz <cmlenz@gmx.de> on 10/04/06 04:39:18.
Alternative approach that also ignores auto_now and auto_now_add fields

Change History

08/02/06 15:37:48 changed by dummy@habmalnefrage.de

  • version changed from magic-removal to SVN.

I always come across theis defect? today. As far as I can see with pdb the self.original_object has 'boolean'-values as 0 and 1, while the new_object has the correct boolean values True and False.

I think that the problem is located in the manager/queryset/loader of the original_object. Didn't found were it is exactly.

08/02/06 16:27:49 changed by dummy@habmalnefrage.de

  • attachment manipulators-bool-changed.diff added.

solution: don't check str()-values, check real values instead

08/02/06 16:29:00 changed by anonymous

  • summary changed from History always records changes to boolean fields to [patch] History always records changes to boolean fields.

10/04/06 04:39:18 changed by Christopher Lenz <cmlenz@gmx.de>

  • attachment django_1511.diff added.

Alternative approach that also ignores auto_now and auto_now_add fields

10/04/06 04:44:56 changed by Christopher Lenz <cmlenz@gmx.de>

  • cc set to cmlenz@gmx.de.

I've added another patch that avoids the duplicate code in the first attached patch. Also, it ignores changes to auto_now and auto_now_add fields, which were also polluting the admin history.

01/08/07 00:30:45 changed by Brian Jackson <brian@iomnis.com>

  • cc changed from cmlenz@gmx.de to cmlenz@gmx.de, brian@iomnis.com.

Is this something that's likely to make it in before 1.0 or should I go with patching. This is the last piece I need to make my client happy.

01/08/07 01:07:11 changed by Brian Jackson <brian@iomnis.com>

I also needed this patch. Same as the last one attached here with the addition of the float case. Without it, I was getting FloatFields? changing every time as well.

-                if not f.primary_key and str(getattr(self.original_object, f.attname)) != str(getattr(new_object, f.attname)):
+                if f.primary_key or getattr(f, 'auto_now', None) \
+                                 or getattr(f, 'auto_now_add', None):
+                    continue
+                newval = getattr(new_object, f.attname)
+                if type(newval) is bool:
+                    cast = bool
+                elif type(newval) is float:
+                       cast = float
+                else:
+                    cast = str
+                if cast(getattr(self.original_object, f.attname)) != cast(newval):

01/25/07 20:39:27 changed by Simon G. <dev@simon.net.nz>

  • stage changed from Unreviewed to Accepted.

08/01/08 09:51:25 changed by lukeplant

  • status changed from new to closed.
  • resolution set to fixed.

I cannot reproduce. My guess is that this disappeared with newforms-admin, since all of the above code is manipulator related, which no longer applies. Please re-open if it is still an issue, with more details about how to reproduce since I can't do so currently.


Add/Change #1511 ([patch] History always records changes to boolean fields)




Change Properties
Action