On 12/04/2014 11:15 PM, Anssi Kääriäinen wrote:
> On Thu, 2014-12-04 at 18:04 -0800, Josh Smeaton wrote:
> 
>>
>> I've implemented https://github.com/django/django/pull/3655/ which
>> effectively ignores the max_digits and decimal_places arguments in the
>> base expression class. Subclasses are free to enforce validation if it
>> is necessary. Further, callers using aren't required to supply bounds
>> checking in this situation.
> 
> It seems wrong to throw away constraints the user has explicitly set.
> So, if you say:
>    
>     .annotate(sum_age=Sum('age', output_field=DecimalField(max_digits=3)))
> 
> then it seems that the max_digits should really be 3.
> 
> So, if the user explicitly asks for max_digits=3 in the output_field
> argument, then we should enforce that. Or, alternatively we should
> disallow setting max_digits for explicit output_field in expressions.
> But just throwing away the value the user has explicitly set is wrong.

I just commented on the ticket with more details, but I think "not
enforcing" is actually the right answer, and consistent with how other
fields behave.

I agree that it's odd that you can provide these validation parameters
(to DecimalField and many other field types) when instantiating them for
output_field, and they won't be enforced, but I don't see a reasonable
way to address that in the general case.

Well, actually, I do see one way - I think it would probably be better
if `output_field` took classes, not instances. But unfortunately I think
that would be quite hard to implement, since `get_internal_type` is an
instance method, not a classmethod.

Carl

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/django-developers.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/5482033B.6010900%40oddbird.net.
For more options, visit https://groups.google.com/d/optout.

Attachment: signature.asc
Description: OpenPGP digital signature

Reply via email to