Adrian Holovaty wrote: >* Specifically, validation happens on Model.__init__() and >Model.__setattr(), > Ouch... Last time this was discussed this was considered bad thing (I may be mistaken) because this doesn't allow any intermediate non-valid state for an object which nonetheless may be useful. I mean if you have have two fields whose values can only be validated in the presense of the other how do you set them if the first __setattr__ blows?
The concept of always keeping object in a correct state is indeed very nice but makes some practicle cases really harder. So I would vote for late validation on save() or explicit validate(). Or! We can devide all validity checks into two groups and perform "basic" validation (like format checking and requiredness) early but delay "interesting" validation for moments where all data ready and user calls save() or validate(). >This can lead to some IntegrityErrors at the database level (search >the django-users mailing list archives for examples) when the >developer forgets to validate. > > save() wouldn't let them forget normally... > c.crime_date = datetime.date(2006, 1, 2) > > c.crime_date = '2006-1-2' > >In the second example, c.crime_date would immediately be converted to >a datetime.date object. What are the pitfalls to this approach? > > -1 This breaks semantics of a property of an object: you should be able to read exactly what you just set. Imagine explaining this magic to a newbie: c.crime_date = request.POST['crime_date'] ## user submits '2006-1-2' if c.crime_date == '2006-1-2': ## false! ... Of course you can define comparision with strings etc... But this leads to even more magic. My point is that it's not an expected behavior. It's much better and expected in Python (if I may say this with my little experience in it :-) ) to do such convertions explicitely with functions. >That's all I had time to write up on a plane trip this evening. >Comments, thoughts, ideas? > > Overall I like it. When I first met Django manipulators I had a hard time understanding why this wrapper is at all needed between data on the web and an object. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django developers" group. To post to this group, send email to django-developers@googlegroups.com To unsubscribe from this group, send email to [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-developers -~----------~----~----~----~------~----~------~--~---