On Sunday 28 February 2016 12:23:50 Florian Apolloner wrote:
> On Sunday, February 28, 2016 at 9:57:27 AM UTC+1, Luke Plant wrote:
> > We could also potentially add another sentinel like
> > DB_MAX_UNICODE_SAFE_LENGTH that works as you expect and is clearly
> > documented, for the sake of 3rd party apps, and comes with the caveat
> > that it produces different behaviour on different databases.
> 
> This is simply not an option as someone (I think Aymeric) already pointed
> out. Technically we do not know DB_MAX_UNICODE_SAFE_LENGTH till the call of
> model.save (since you can supply a using argument there), this means forms
> will never know the max length and could not perform any validation.

...or it could just mean we take the minimum of all defined databases (we would 
probably like to ask the routers for the db_for_write, but this requires the 
model to be defined already, so we can't do that).

No, this is still a problem: During the development, you decide to add a 
second database, and all of the sudden get migrations for the whole project, 
because the minimum over all defined databases changed. No good. So, I'd modify 
it to something like 

        django.db.max_unicode_safe_length(database=DEFAULT_DB_ALIAS)

However, as I explained earlier, DB_MAX_UNICODE_SAFE_LENGTH is not a suitable 
default for max_length, so this is a little besides the point here.

On Sunday 28 February 2016 10:57:17 Luke Plant wrote:
> 
> Django should not be settling low arbitrary limits for the sake of a
> database I'm not even using, that's just crazy. Limits as high as 120 are
> not "big enough for anyone"

Defaults are not limits, and I don't think anybody setting a default expects 
that it would fit everyone. If we did, we'd consider removing the argument 
completely.

> Maximum field length is a critical value that must not be left
> to some default, because as soon as you come to interoperate with other
> systems, it *does* matter.
> 
> So, this needs to be explicit.

Erg, again -- nobody is suggesting to make users unable to set their own 
max_length; but many Django projects actually do not need interaction with 
other systems. These are probably the majority of projects, and even a bigger 
part of the projects done by beginners. We can remove an obstacle by saying, 
"unless you have reason to think otherwise, we suggest that 120 is a good 
length for a field intended to hold one line of text". It is an obstacle both 
because beginners these days are not used to think of length limits (since the 
programming language has a string type), and because they are quite likely to 
get it wrong (either make it too short, or go over MySql's limit of 191).

So, to summarise: I think the database-relative constants you proposed are a 
good idea; but I don't think any of them fits the bill of a default, and I do 
think a default will do more good than harm.

Shai. 

Reply via email to