![]() When I dug into this issue in preparing to commit the patch here, I realized that this bug is a case where ModelForm currently promises something (validation of "incomplete" models) that isn't possible to deliver in a way that is consistently correct. I did want to get this resolved in some way for Django 1.4. Hmm, there was extensive discussion of this on the mailing list around the time that patch was worked on apparently it never got summarized here I should have done that. That being said, I did change things so that they would look a little bit more like Russel's example in #13249. Because is_valid only calculates its the form errors once (after which they are cached), all of this has to be done before is_valid is called, and updating form.instance seems to be the easiest way. The validate_unique() call needs to be made only after the final values are set on the ORM instance, otherwise the check will not catch the kinds of errors that we are trying to catch prior to the database being hit. I realize that setting values on form.instance prior to calling form.is_valid() is not the normal approach, but I am not sure if there is any other approach that makes as much sense. ![]() I do not see anything comparable in #15326. The patch I just attached should address all of your issues, Carl, except that I don't quite understand what you are referring to in your last bullet, regarding setting form.instance prior to validation. It's late so I won't guarantee there isn't more that I'm missing, but that's what I see on first review. It would be better to replace that test with a case like the one in the #15326 report, a real-world case that is currently broken. in the admin), nor is it a documented pattern we need to ensure works. The test where values are set on form.instance prior to validation isn't really relevant, because that's not something Django does internally (e.g.In particular, I think a CharField blank=True but with no default specified could still break if there's a record in the database with that field blank, because empty string is the implicit default. I'm not sure checking if default is NOT_PROVIDED is actually sufficient.Why does the admin list_editable test post values for t3 in the POST data when that field is not in list_editable? Does the admin actually post values from hidden inputs for all fields not included in list_editable? This test should be checked to make sure it matches what the admin actually does.Given the new logic, I think it would be clearer to drop the use of for.else and just have a boolean perform_check that gets flipped True if any field in the check is found to not be excluded and not have a default (and when its flipped to True you can break from the loop) and then after the loop use the boolean to decide whether to add the check to the unique_checks list. The use of check_count is a bit convoluted and hard to understand. ![]() get_field_by_name() method and discard the values you don't need in the returned tuple. This patch doesn't require adding another method to model _meta it's already bloated.The "as of Django 1.2" note in the unique_together docs should use the versionadded marker.The versionadded note in the validate_unique docs should probably go right below the modified paragraph, not at the top of the section.However it isn't very informative (only "Please correct the errors below." but nothing below is indicated). In case when all fields from unique_together are in list_editable, the error message does show. Integrity Error is raised when for example having two rows -Īnd trying to change the t2 in first row to 'a'. The changelist form (?) doesn't check the uniqueness of an edited record. T3 = models.CharField(max_length=255, blank=True, null=True) T2 = models.CharField(max_length=255, blank=True, null=True) T1 = models.CharField(max_length=255, blank=True, null=True) Registered with list_editable containing some of that fields (not all of them). I'm getting an Integrity Error when trying to edit (on changelist) a model that has some unique_together fields and is
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |