Re: [Django] #22097: IntegerField with given choices leads to wrong has_changed() work

2023-07-14 Thread Django
#22097: IntegerField with given choices leads to wrong has_changed() work
-+
 Reporter:  igor.mitrenko@…  |Owner:  Claude Paroz
 Type:  Bug  |   Status:  closed
Component:  Forms|  Version:  1.7-alpha-1
 Severity:  Release blocker  |   Resolution:  fixed
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+
Changes (by Mariusz Felisiak):

 * status:  new => closed
 * resolution:   => fixed


Comment:

 GHPS, please don't reopen old already fixed issue. If you believe it's an
 issue in Django, then please create a new ticket in Trac and follow our
 [https://docs.djangoproject.com/en/dev/internals/contributing/bugs-and-
 features/#reporting-bugs bug reporting guidelines].

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070189557334b0-97d42d84-17d5-4d65-b533-ce439dc6f2cc-00%40eu-central-1.amazonses.com.


Re: [Django] #22097: IntegerField with given choices leads to wrong has_changed() work

2023-07-14 Thread Django
#22097: IntegerField with given choices leads to wrong has_changed() work
-+
 Reporter:  igor.mitrenko@…  |Owner:  Claude Paroz
 Type:  Bug  |   Status:  new
Component:  Forms|  Version:  4.2
 Severity:  Release blocker  |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+
Changes (by GHPS):

 * cc: GHPS (added)
 * version:  1.7-alpha-1 => 4.2


-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/01070189554bee99-52ac6354-5881-4083-9f1b-5d12152410f2-00%40eu-central-1.amazonses.com.


Re: [Django] #22097: IntegerField with given choices leads to wrong has_changed() work

2023-07-14 Thread Django
#22097: IntegerField with given choices leads to wrong has_changed() work
-+
 Reporter:  igor.mitrenko@…  |Owner:  Claude Paroz
 Type:  Bug  |   Status:  new
Component:  Forms|  Version:  1.7-alpha-1
 Severity:  Release blocker  |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+
Changes (by GHPS):

 * status:  closed => new
 * resolution:  fixed =>


Comment:

 Summary:

 While trying to find out why the forms in two different applications are
 marked for saving even if no field has been changed, I could pin the
 problem down
 to the integer enum fields used in both models and form.ChoiceField
 involved.
 In short form.has_changed() is triggered because of a double data
 conversion
 during the round-trip.

 The value of the integer enum field is converted to a string and rendered.
 The POST request comes back with this string which gets compared to the
 original
 enum integer which shows that they are different. During the - unnecessary
 - saving
 the string becomes an int again - which is why the original problem is
 hidden
 from the perspective of a user.

 I found this old ticket and it looks to me like the nine year old bug has
 shown its ugly face again.

 Background:

 Take the following enum and create a model field in model.py:

 {{{

 class eAssets(models.IntegerChoices):
 dvd   =1, _('DVD')
 bluray=3, _('Blu-ray')
 none  =0, _('-')

 eAsset=models.PositiveSmallIntegerField(choices=eAssets.choices,
 default=eAssets.none)
 }}}


 Create a choice form field in form.py:

 {{{

 eAsset=forms.ChoiceField(label=mdMovie._meta.get_field('eAsset').verbose_name,
 choices=[(dcEntry.value, dcEntry.label) for dcEntry in mdMovie.eAssets],
   initial=mdMovie.eAssets.none)

 After processing the POST request, form.has_changed() is always true in
 view.py:

 fmForm=fmMovie(vRequest.POST, vRequest.FILES or None,
 instance=rcCurrentMovie)
 fmForm.has_changed()
 True
 fmForm.changed_data
 ['eAsset']
 }}}


 Links:
 On Stackoverflow someone reported the same problem.
 [https://stackoverflow.com/questions/68763230/django-forms-a-dynamic-
 integer-model-choice-field-always-fails-form-has-changed|A dynamic integer
 model choice field always fails form.has_changed()]

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/010701895541de0b-303ed10e-39e1-49c8-8814-dc8f3f38b037-00%40eu-central-1.amazonses.com.


Re: [Django] #22097: IntegerField with given choices leads to wrong has_changed() work

2014-02-20 Thread Django
#22097: IntegerField with given choices leads to wrong has_changed() work
-+---
 Reporter:  igor.mitrenko@…  |Owner:  claudep
 Type:  Bug  |   Status:  closed
Component:  Forms|  Version:  1.7-alpha-1
 Severity:  Release blocker  |   Resolution:  fixed
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+---
Changes (by Claude Paroz ):

 * status:  assigned => closed
 * resolution:   => fixed


Comment:

 In [changeset:"cb844497d01ddb45603e47891cdf36ae0b006d03"]:
 {{{
 #!CommitTicketReference repository=""
 revision="cb844497d01ddb45603e47891cdf36ae0b006d03"
 Fixed #22097 -- Fixed change detection for TypedChoiceField

 Thanks Igor Mitrenko for the report.
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/081.61bf33db2598204db180ab4f5f7a1279%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


Re: [Django] #22097: IntegerField with given choices leads to wrong has_changed() work

2014-02-20 Thread Django
#22097: IntegerField with given choices leads to wrong has_changed() work
-+---
 Reporter:  igor.mitrenko@…  |Owner:  claudep
 Type:  Bug  |   Status:  assigned
Component:  Forms|  Version:  1.7-alpha-1
 Severity:  Release blocker  |   Resolution:
 Keywords:   | Triage Stage:  Accepted
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+---
Changes (by claudep):

 * status:  new => assigned
 * severity:  Normal => Release blocker
 * needs_better_patch:   => 0
 * needs_tests:   => 0
 * owner:  nobody => claudep
 * needs_docs:   => 0
 * stage:  Unreviewed => Accepted


Comment:

 This regression was introduced in a0f3eeccf3d5a90f9914bfe20b15df05673ea59d
 in response to the use case described in #21397.

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/081.dfbaa39aff70e945527e20cc0224653e%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.


[Django] #22097: IntegerField with given choices leads to wrong has_changed() work

2014-02-19 Thread Django
#22097: IntegerField with given choices leads to wrong has_changed() work
-+-
 Reporter:  igor.mitrenko@…  |  Owner:  nobody
 Type:  Bug  | Status:  new
Component:  Forms|Version:  1.7-alpha-1
 Severity:  Normal   |   Keywords:
 Triage Stage:  Unreviewed   |  Has patch:  0
Easy pickings:  0|  UI/UX:  0
-+-
 It seems that providing choices to IntegerField makes ModelForm (created
 by admin, for example) to use ChoiceField and call it's to_python method,
 which return string. Finally, _has_changed method compares initial value
 (of type int) to new value (of type unicode), and always returns True.
 My code sending "object created" signals on each inline object change, so
 it leads to creation of unnecessary "changed" events logging.

 Snippet:
 {{{
 ...
 class PhoneNumber(models.Model):
 """
 Phone number set for workers
 """
 MOBILE_PHONE = 0
 WORK_PHONE = 1
 HOME_PHONE = 2
 KIND_CHOICES = (
 (MOBILE_PHONE, _('Mobile')),
 (WORK_PHONE, _('Work')),
 (HOME_PHONE, pgettext('kind of phone number', 'Home')),
 )
 worker = models.ForeignKey(Worker)
 phone_number = models.CharField(_('phone number'), max_length=12)
 kind = models.SmallIntegerField(_('kind of number'),
 choices=KIND_CHOICES, default=MOBILE_PHONE)
 ...
 }}}
 ModelForm derived from such a model created ChoiceField for kind, but it's
 has_changed method return True always, cause it's (as example) always 1 !=
 u'1'

 Removing choices argument is a workaround, but it breaks desired
 behaviour.
 Another workaround is to use CharField, but the problem still remains.
 Django version 1.7.dev20131210091409

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.57988ff4f124cebcfefa87991b82bf89%40djangoproject.com.
For more options, visit https://groups.google.com/groups/opt_out.