Also: inline. On Wednesday, September 27, 2017 at 4:55:32 PM UTC+2, [email protected] wrote: > > Please find comment inline > > On Friday, 22 September 2017 15:44:38 UTC+5:30, Sjoerd Job Postmus wrote: >> >> Indeed it could be! >> >> What if it was not `string_if_invalid` but `if_invalid`. The value could >> be: >> >> * An Exception instance (which would then be raised) >> * An Exception class (which would be instantiated with the "invalid" >> thing), and then be raised >> * A callable (which would be called, and must return a string or raise), >> and the result used (unless it raises an exception, in which case that >> exception is propogated upwards) >> * A string (which would be interpolated with `%` if it contains "%s") to >> be used instead. >> > This seems like an overkill. What if we instead provide an additional > boolean flag `raise_if_invalid` >
I do agree that the above specification seems overkill. However, I think that a boolean flag `raise_if_invalid` is the wrong approach: One could have both `string_if_invalid` defined and `raise_if_invalid` (and will we also add `log_if_invalid`?). For simplicity, having an `if_invalid` that is a callable that either returns a string (or raises an exception) seems to be the most generic approach. For Django it's "always call the function" (the default simply would be `return ''`). One can add all the logic one wants into that specific function: raising exceptions, logging, returning a string (like `string_if_invalid`?) All the other options (Exception instances and classes and strings) are indeed overkill (it can be handled by that function I mentioned), but would allow for a simpler `settings.py`. -- 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 https://groups.google.com/group/django-developers. To view this discussion on the web visit https://groups.google.com/d/msgid/django-developers/75152154-6a86-4d4a-8513-faea06d556b6%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
