Re: Defaulting to use BigAutoField in models

2020-07-12 Thread Tom Forbes
d not much else 
>>> has happened since then.
>>>
>>> As many of you are aware the max value a standard AutoField can hold is 
>>> 2,147,483,647 (2.1 billion) which sounds like more than you can ever need. 
>>> But it’s often not, and you only find out at the worst possible time - out 
>>> of the blue at night and during a period of rapid growth. The process for 
>>> fixing this issue also becomes a lot harder as your data grows - when 
>>> you’ve hit the limit you’re looking at a multi-hour `ALTER TABLE` on 
>>> Postgres during which writes and reads are blocked, or a risky operation to 
>>> create a new table with the correct primary key and copy old data over in 
>>> batches. Basically if you’ve experienced this before you wouldn’t wish it 
>>> on your worst enemy.
>>>
>>> I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements 
>>> welcome!) setting that _defaults_ to `BigAutoField`, with prominent 
>>> docs/release notes saying that to preserve the existing behaviour this 
>>> should be set to `AutoField`. I think this the only realistic way we can 
>>> implement this for new projects in a way that ensures it will be used 
>>> meaningfully and not forgotten about until it’s too late.
>>>
>>> Rails managed to do this migration somewhat painlessly due the big 
>>> differences between Rails and Django models. As Django migrations are 
>>> derived from the current model state so there’s no way I can think of to 
>>> express “make this auto-generated field a BigAutoField only if this model 
>>> is *new*”. The way I see it is that a global setting is very easy to 
>>> toggle and there is little chance of missing the large numbers of 
>>> migrations that would be generated during the Django update. Smaller 
>>> applications could apply the migrations with little issue and larger 
>>> applications would be able to opt-out (as well as be reminded that this is 
>>> a problem they could face!).
>>>
>>> Some specifics:
>>> - The setting would take any dotted path to a class, or a single class 
>>> name for a build in field. This would potentially solve [3], and could be 
>>> useful to people who want to default to other fields like UUIDs (or a 
>>> custom BigAutoField) for whatever reason
>>> - The setting would also be used for GenericForeignKeys, which right now 
>>> are backed by a PositiveIntegerField and so suffer from the same AutoField 
>>> limitations
>>>
>>> Any thoughts on this?
>>>
>>> Tom
>>>
>>> 1. 
>>> https://groups.google.com/d/msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ
>>>
>>> 2. https://github.com/django/django/pull/8924/
>>>
>>> 3. https://code.djangoproject.com/ticket/56 
>>> <https://groups.google.com/d/msg/django-developers/VFXZpHnuEJc/bbefjX9yCQAJ>
>>>
>>>
>>>
>>>

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/2c853449-c519-4605-be23-4faa21ed40d4n%40googlegroups.com.


Re: Defaulting to use BigAutoField in models

2020-06-28 Thread Tom Forbes

I spent some time last week experimenting with my patch, the biggest issue 
I could find was that under some situations we add explicit casts to array 
fields in Postgres based on the *expected* PK field type (i.e `WHERE 
[1,2,3]::int @> [1,2,3]::bigint`) which causes the query to be invalid. The 
casts all look redundant however working out when they are redundant is 
pretty complex, so I'm not sure if this approach has any legs.

> Regarding third party apps a solution could be to allow a per-app config 
option or encourage them to explicitly choose which primary key they use 
for their model but I'm not a big fan of baking logic in the migration 
framework to treat some fields in a special way.

Auto-generated M2M tables are an issue here, we would need to add some 
option to ManyToManyField() to allow passing in a PK field type. But I like 
the approach of just saying "if you ship migrations, be explicit about your 
primary keys" as it seems pretty simple.

Overall I think your two phase plan seems like a good approach  - lets do 
it?

On Thursday, 18 June 2020 at 15:18:35 UTC+1 charettes wrote:

> +1 from me as well but I don't think we should add any logic to the 
> migration framework to handle the transition.
>
> I think the release plan should be something along the following
>
> Phase 1:
> - New projects are generated with MODEL_DEFAULT_PK = 
> 'django.db.models.BigAutoField'
> - A system check or warning is emitted when the setting is not defined and 
> MODEL_DEFAULT_PK default to 'django.db.models.AutoField' during the 
> transition period. The warning should warn that the value will default to 
> 'django.db.models.AutoField' in a future version of Django.
> - An upgrade path is mentioned in the docs to mention that explicit ` id = 
> AutoField()` must be assigned to preserve previous behaviour and avoid 
> migrations. This one of the thing projects such as django-codemod could 
> really help with[0]
>
> Phase 2:
> - settings.MODEL_DEFAULT_PK now defaults to 'django.db.models.BigAutoField'
> - System check/warning about undefined MODEL_DEFAULT_PK setting is removed.
> - Let the migration framework generate migrations just like it normally 
> would for projects that didn't follow the documented migration path.
> - Optionally add a system check that warns about usage of `AutoField` 
> because of its possible overflow.
>
> > I think we should restrict the setting between normal and big auto 
> fields only. Allowing UUID's would be changing the type, with the potential 
> for havoc with code incompalities throughout django. It's also not possible 
> to migrate tables over to the new type.
>
> I'm not sure I agree here. For folks that are setting a up a new project 
> starting with UUIDField primary keys can be useful and if we're adding a 
> setting for this purpose I think we should it make it as flexible as 
> possible.
>
>
> [0] https://github.com/browniebroke/django-codemod
>
> Le jeudi 11 juin 2020 11:28:59 UTC-4, Tom Forbes a écrit :
>>
>> I’d like to re-propose switching Django to use BigAutoField’s rather than 
>> the current AutoField. This has been proposed[1] before (and a MR made[2]) 
>> but it was closed due to implementation issues and not much else has 
>> happened since then.
>>
>> As many of you are aware the max value a standard AutoField can hold is 
>> 2,147,483,647 (2.1 billion) which sounds like more than you can ever need. 
>> But it’s often not, and you only find out at the worst possible time - out 
>> of the blue at night and during a period of rapid growth. The process for 
>> fixing this issue also becomes a lot harder as your data grows - when 
>> you’ve hit the limit you’re looking at a multi-hour `ALTER TABLE` on 
>> Postgres during which writes and reads are blocked, or a risky operation to 
>> create a new table with the correct primary key and copy old data over in 
>> batches. Basically if you’ve experienced this before you wouldn’t wish it 
>> on your worst enemy.
>>
>> I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements 
>> welcome!) setting that _defaults_ to `BigAutoField`, with prominent 
>> docs/release notes saying that to preserve the existing behaviour this 
>> should be set to `AutoField`. I think this the only realistic way we can 
>> implement this for new projects in a way that ensures it will be used 
>> meaningfully and not forgotten about until it’s too late.
>>
>> Rails managed to do this migration somewhat painlessly due the big 
>> differences between Rails and Django models. As Django migrations are 
>> derived from the current model state so there’s no way I can think of to 
>> express “make this auto-generated field a BigAu

Re: Defaulting to use BigAutoField in models

2020-06-18 Thread charettes
Email got sent too fast

I meant

> The warning should warn that the value will default to 
'django.db.models.BigAutoField' in a future version of Django.

Regarding third party apps a solution could be to allow a per-app config 
option or encourage them to explicitly choose which primary key they use 
for their model but I'm not a big fan of baking logic in the migration 
framework to treat some fields in a special way.

Simon

Le jeudi 18 juin 2020 10:18:35 UTC-4, charettes a écrit :
>
> +1 from me as well but I don't think we should add any logic to the 
> migration framework to handle the transition.
>
> I think the release plan should be something along the following
>
> Phase 1:
> - New projects are generated with MODEL_DEFAULT_PK = 
> 'django.db.models.BigAutoField'
> - A system check or warning is emitted when the setting is not defined and 
> MODEL_DEFAULT_PK default to 'django.db.models.AutoField' during the 
> transition period. The warning should warn that the value will default to 
> 'django.db.models.AutoField' in a future version of Django.
> - An upgrade path is mentioned in the docs to mention that explicit ` id = 
> AutoField()` must be assigned to preserve previous behaviour and avoid 
> migrations. This one of the thing projects such as django-codemod could 
> really help with[0]
>
> Phase 2:
> - settings.MODEL_DEFAULT_PK now defaults to 'django.db.models.BigAutoField'
> - System check/warning about undefined MODEL_DEFAULT_PK setting is removed.
> - Let the migration framework generate migrations just like it normally 
> would for projects that didn't follow the documented migration path.
> - Optionally add a system check that warns about usage of `AutoField` 
> because of its possible overflow.
>
> > I think we should restrict the setting between normal and big auto 
> fields only. Allowing UUID's would be changing the type, with the potential 
> for havoc with code incompalities throughout django. It's also not possible 
> to migrate tables over to the new type.
>
> I'm not sure I agree here. For folks that are setting a up a new project 
> starting with UUIDField primary keys can be useful and if we're adding a 
> setting for this purpose I think we should it make it as flexible as 
> possible.
>
>
> [0] https://github.com/browniebroke/django-codemod
>
> Le jeudi 11 juin 2020 11:28:59 UTC-4, Tom Forbes a écrit :
>>
>> I’d like to re-propose switching Django to use BigAutoField’s rather than 
>> the current AutoField. This has been proposed[1] before (and a MR made[2]) 
>> but it was closed due to implementation issues and not much else has 
>> happened since then.
>>
>> As many of you are aware the max value a standard AutoField can hold is 
>> 2,147,483,647 (2.1 billion) which sounds like more than you can ever need. 
>> But it’s often not, and you only find out at the worst possible time - out 
>> of the blue at night and during a period of rapid growth. The process for 
>> fixing this issue also becomes a lot harder as your data grows - when 
>> you’ve hit the limit you’re looking at a multi-hour `ALTER TABLE` on 
>> Postgres during which writes and reads are blocked, or a risky operation to 
>> create a new table with the correct primary key and copy old data over in 
>> batches. Basically if you’ve experienced this before you wouldn’t wish it 
>> on your worst enemy.
>>
>> I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements 
>> welcome!) setting that _defaults_ to `BigAutoField`, with prominent 
>> docs/release notes saying that to preserve the existing behaviour this 
>> should be set to `AutoField`. I think this the only realistic way we can 
>> implement this for new projects in a way that ensures it will be used 
>> meaningfully and not forgotten about until it’s too late.
>>
>> Rails managed to do this migration somewhat painlessly due the big 
>> differences between Rails and Django models. As Django migrations are 
>> derived from the current model state so there’s no way I can think of to 
>> express “make this auto-generated field a BigAutoField only if this model 
>> is *new*”. The way I see it is that a global setting is very easy to 
>> toggle and there is little chance of missing the large numbers of 
>> migrations that would be generated during the Django update. Smaller 
>> applications could apply the migrations with little issue and larger 
>> applications would be able to opt-out (as well as be reminded that this is 
>> a problem they could face!).
>>
>> Some specifics:
>> - The setting would take any dotted path to a class, or a single class 
>> name for a build in field. This would potential

Re: Defaulting to use BigAutoField in models

2020-06-18 Thread charettes
+1 from me as well but I don't think we should add any logic to the 
migration framework to handle the transition.

I think the release plan should be something along the following

Phase 1:
- New projects are generated with MODEL_DEFAULT_PK = 
'django.db.models.BigAutoField'
- A system check or warning is emitted when the setting is not defined and 
MODEL_DEFAULT_PK default to 'django.db.models.AutoField' during the 
transition period. The warning should warn that the value will default to 
'django.db.models.AutoField' in a future version of Django.
- An upgrade path is mentioned in the docs to mention that explicit ` id = 
AutoField()` must be assigned to preserve previous behaviour and avoid 
migrations. This one of the thing projects such as django-codemod could 
really help with[0]

Phase 2:
- settings.MODEL_DEFAULT_PK now defaults to 'django.db.models.BigAutoField'
- System check/warning about undefined MODEL_DEFAULT_PK setting is removed.
- Let the migration framework generate migrations just like it normally 
would for projects that didn't follow the documented migration path.
- Optionally add a system check that warns about usage of `AutoField` 
because of its possible overflow.

> I think we should restrict the setting between normal and big auto fields 
only. Allowing UUID's would be changing the type, with the potential for 
havoc with code incompalities throughout django. It's also not possible to 
migrate tables over to the new type.

I'm not sure I agree here. For folks that are setting a up a new project 
starting with UUIDField primary keys can be useful and if we're adding a 
setting for this purpose I think we should it make it as flexible as 
possible.


[0] https://github.com/browniebroke/django-codemod

Le jeudi 11 juin 2020 11:28:59 UTC-4, Tom Forbes a écrit :
>
> I’d like to re-propose switching Django to use BigAutoField’s rather than 
> the current AutoField. This has been proposed[1] before (and a MR made[2]) 
> but it was closed due to implementation issues and not much else has 
> happened since then.
>
> As many of you are aware the max value a standard AutoField can hold is 
> 2,147,483,647 (2.1 billion) which sounds like more than you can ever need. 
> But it’s often not, and you only find out at the worst possible time - out 
> of the blue at night and during a period of rapid growth. The process for 
> fixing this issue also becomes a lot harder as your data grows - when 
> you’ve hit the limit you’re looking at a multi-hour `ALTER TABLE` on 
> Postgres during which writes and reads are blocked, or a risky operation to 
> create a new table with the correct primary key and copy old data over in 
> batches. Basically if you’ve experienced this before you wouldn’t wish it 
> on your worst enemy.
>
> I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements 
> welcome!) setting that _defaults_ to `BigAutoField`, with prominent 
> docs/release notes saying that to preserve the existing behaviour this 
> should be set to `AutoField`. I think this the only realistic way we can 
> implement this for new projects in a way that ensures it will be used 
> meaningfully and not forgotten about until it’s too late.
>
> Rails managed to do this migration somewhat painlessly due the big 
> differences between Rails and Django models. As Django migrations are 
> derived from the current model state so there’s no way I can think of to 
> express “make this auto-generated field a BigAutoField only if this model 
> is *new*”. The way I see it is that a global setting is very easy to 
> toggle and there is little chance of missing the large numbers of 
> migrations that would be generated during the Django update. Smaller 
> applications could apply the migrations with little issue and larger 
> applications would be able to opt-out (as well as be reminded that this is 
> a problem they could face!).
>
> Some specifics:
> - The setting would take any dotted path to a class, or a single class 
> name for a build in field. This would potentially solve [3], and could be 
> useful to people who want to default to other fields like UUIDs (or a 
> custom BigAutoField) for whatever reason
> - The setting would also be used for GenericForeignKeys, which right now 
> are backed by a PositiveIntegerField and so suffer from the same AutoField 
> limitations
>
> Any thoughts on this?
>
> Tom
>
> 1. 
> https://groups.google.com/d/msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ
>
> 2. https://github.com/django/django/pull/8924/
>
> 3. https://code.djangoproject.com/ticket/56 
> <https://groups.google.com/d/msg/django-developers/VFXZpHnuEJc/bbefjX9yCQAJ>
>
>
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django developers  (Contributions to Django itself)" group.
To 

Re: Defaulting to use BigAutoField in models

2020-06-18 Thread Adam Johnson
This would make the change only affect existing installs of third party
apps. I think documentation on using RunSQL() in a migration (in a project
app) could be warranted.

On Thu, 18 Jun 2020 at 14:50, Caio Ariede  wrote:

> What about third party apps?
>
> It would be great to migrate every AutoField to BigAutoField without the
> need to specify them manually.
>
>
> --
> Caio
>
>
>
> On 18 Jun 2020, at 09:40, Adam Johnson  wrote:
>
> Would we be able to provide instructions on how to migrate from SIGNED INT
>> to UNSIGNED BIG INT? Perhaps a management command that outputs SQL like
>> sqlmigrate?
>>
>
> It would only be needed to add this to the model:
> id = BigAutoField()
>
> Then migrations would pick it up, because the field is no longer
> auto_created.
>
> On Thu, 18 Jun 2020 at 13:24, Caio Ariede  wrote:
>
>>
>> On 17 Jun 2020, at 16:56, Adam Johnson  wrote:
>>
>> I think special casing the migrations framework is an avenue to explore,
>>> so I created this today and to my surprise it seems to work quite well:
>>> https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839
>>> .
>>
>>
>> That is a pretty neat solution. I think it would work quite well.
>>
>>
>> I really like that solution as well, it’s pretty fair :)
>>
>>
>>
>> What about a way to warn users approaching the limit? I think a database
>> check that detects AutoFields where the next ID is >50% of the way through
>> would be a good solution. That's the kind of monitoring I've built in the
>> past.
>>
>> (50% might sound like it's near the limit, but the table is growing with
>> an exponential curve, even quite shallow, it's quite close in terms of
>> time.)
>>
>>
>> I think this is indeed a good to have.
>>
>> Would we be able to provide instructions on how to migrate from SIGNED
>> INT to UNSIGNED BIG INT? Perhaps a management command that outputs SQL like
>> sqlmigrate?
>>
>>
>> --
>> Caio
>>
>> --
>> 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 django-developers+unsubscr...@googlegroups.com.
>> To view this discussion on the web visit
>> https://groups.google.com/d/msgid/django-developers/5ECD26CA-339E-4954-A0BA-E7D8296E6988%40gmail.com
>> <https://groups.google.com/d/msgid/django-developers/5ECD26CA-339E-4954-A0BA-E7D8296E6988%40gmail.com?utm_medium=email_source=footer>
>> .
>>
>
>
> --
> Adam
>
> --
> 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 django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/CAMyDDM0W-8ywE%3D3fHpdoMn3%3Dw-3J%2BN2e_nEgJHaNYia-3Xv%2BWw%40mail.gmail.com
> <https://groups.google.com/d/msgid/django-developers/CAMyDDM0W-8ywE%3D3fHpdoMn3%3Dw-3J%2BN2e_nEgJHaNYia-3Xv%2BWw%40mail.gmail.com?utm_medium=email_source=footer>
> .
>
>
> --
> 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 django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/AFE3161D-6571-46B1-AAD3-C21E4A9CE0C0%40gmail.com
> <https://groups.google.com/d/msgid/django-developers/AFE3161D-6571-46B1-AAD3-C21E4A9CE0C0%40gmail.com?utm_medium=email_source=footer>
> .
>


-- 
Adam

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM2PYgN6Nnyk%3D2khTzZELBJbDotueQOAV%3DfJFv4zOA0KPA%40mail.gmail.com.


Re: Defaulting to use BigAutoField in models

2020-06-18 Thread Caio Ariede
What about third party apps?

It would be great to migrate every AutoField to BigAutoField without the need 
to specify them manually.


--
Caio



> On 18 Jun 2020, at 09:40, Adam Johnson  wrote:
> 
> Would we be able to provide instructions on how to migrate from SIGNED INT to 
> UNSIGNED BIG INT? Perhaps a management command that outputs SQL like 
> sqlmigrate?
> 
> It would only be needed to add this to the model:
> id = BigAutoField() 
> 
> Then migrations would pick it up, because the field is no longer auto_created.
> 
> On Thu, 18 Jun 2020 at 13:24, Caio Ariede  <mailto:caio.ari...@gmail.com>> wrote:
> 
>> On 17 Jun 2020, at 16:56, Adam Johnson > <mailto:m...@adamj.eu>> wrote:
>> 
>> I think special casing the migrations framework is an avenue to explore, so 
>> I created this today and to my surprise it seems to work quite well: 
>> https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839
>>  
>> <https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839>.
>> 
>> That is a pretty neat solution. I think it would work quite well.
> 
> I really like that solution as well, it’s pretty fair :)
> 
> 
>> 
>> What about a way to warn users approaching the limit? I think a database 
>> check that detects AutoFields where the next ID is >50% of the way through 
>> would be a good solution. That's the kind of monitoring I've built in the 
>> past.
>> 
>> (50% might sound like it's near the limit, but the table is growing with an 
>> exponential curve, even quite shallow, it's quite close in terms of time.)
>> 
> 
> I think this is indeed a good to have.
> 
> Would we be able to provide instructions on how to migrate from SIGNED INT to 
> UNSIGNED BIG INT? Perhaps a management command that outputs SQL like 
> sqlmigrate?
> 
> 
> --
> Caio
> 
> -- 
> 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 django-developers+unsubscr...@googlegroups.com 
> <mailto:django-developers+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/5ECD26CA-339E-4954-A0BA-E7D8296E6988%40gmail.com
>  
> <https://groups.google.com/d/msgid/django-developers/5ECD26CA-339E-4954-A0BA-E7D8296E6988%40gmail.com?utm_medium=email_source=footer>.
> 
> 
> -- 
> Adam
> 
> -- 
> 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 django-developers+unsubscr...@googlegroups.com 
> <mailto:django-developers+unsubscr...@googlegroups.com>.
> To view this discussion on the web visit 
> https://groups.google.com/d/msgid/django-developers/CAMyDDM0W-8ywE%3D3fHpdoMn3%3Dw-3J%2BN2e_nEgJHaNYia-3Xv%2BWw%40mail.gmail.com
>  
> <https://groups.google.com/d/msgid/django-developers/CAMyDDM0W-8ywE%3D3fHpdoMn3%3Dw-3J%2BN2e_nEgJHaNYia-3Xv%2BWw%40mail.gmail.com?utm_medium=email_source=footer>.

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/AFE3161D-6571-46B1-AAD3-C21E4A9CE0C0%40gmail.com.


Re: Defaulting to use BigAutoField in models

2020-06-18 Thread Adam Johnson
>
> Would we be able to provide instructions on how to migrate from SIGNED INT
> to UNSIGNED BIG INT? Perhaps a management command that outputs SQL like
> sqlmigrate?
>

It would only be needed to add this to the model:
id = BigAutoField()

Then migrations would pick it up, because the field is no longer
auto_created.

On Thu, 18 Jun 2020 at 13:24, Caio Ariede  wrote:

>
> On 17 Jun 2020, at 16:56, Adam Johnson  wrote:
>
> I think special casing the migrations framework is an avenue to explore,
>> so I created this today and to my surprise it seems to work quite well:
>> https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839
>> .
>
>
> That is a pretty neat solution. I think it would work quite well.
>
>
> I really like that solution as well, it’s pretty fair :)
>
>
>
> What about a way to warn users approaching the limit? I think a database
> check that detects AutoFields where the next ID is >50% of the way through
> would be a good solution. That's the kind of monitoring I've built in the
> past.
>
> (50% might sound like it's near the limit, but the table is growing with
> an exponential curve, even quite shallow, it's quite close in terms of
> time.)
>
>
> I think this is indeed a good to have.
>
> Would we be able to provide instructions on how to migrate from SIGNED INT
> to UNSIGNED BIG INT? Perhaps a management command that outputs SQL like
> sqlmigrate?
>
>
> --
> Caio
>
> --
> 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 django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/5ECD26CA-339E-4954-A0BA-E7D8296E6988%40gmail.com
> <https://groups.google.com/d/msgid/django-developers/5ECD26CA-339E-4954-A0BA-E7D8296E6988%40gmail.com?utm_medium=email_source=footer>
> .
>


-- 
Adam

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM0W-8ywE%3D3fHpdoMn3%3Dw-3J%2BN2e_nEgJHaNYia-3Xv%2BWw%40mail.gmail.com.


Re: Defaulting to use BigAutoField in models

2020-06-18 Thread Caio Ariede

> On 17 Jun 2020, at 16:56, Adam Johnson  wrote:
> 
> I think special casing the migrations framework is an avenue to explore, so I 
> created this today and to my surprise it seems to work quite well: 
> https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839 
> .
> 
> That is a pretty neat solution. I think it would work quite well.

I really like that solution as well, it’s pretty fair :)


> 
> What about a way to warn users approaching the limit? I think a database 
> check that detects AutoFields where the next ID is >50% of the way through 
> would be a good solution. That's the kind of monitoring I've built in the 
> past.
> 
> (50% might sound like it's near the limit, but the table is growing with an 
> exponential curve, even quite shallow, it's quite close in terms of time.)
> 

I think this is indeed a good to have.

Would we be able to provide instructions on how to migrate from SIGNED INT to 
UNSIGNED BIG INT? Perhaps a management command that outputs SQL like sqlmigrate?


--
Caio

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/5ECD26CA-339E-4954-A0BA-E7D8296E6988%40gmail.com.


Re: Defaulting to use BigAutoField in models

2020-06-17 Thread Adam Johnson
>
> I think special casing the migrations framework is an avenue to explore,
> so I created this today and to my surprise it seems to work quite well:
> https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839
> .


That is a pretty neat solution. I think it would work quite well.

What about a way to warn users approaching the limit? I think a database
check that detects AutoFields where the next ID is >50% of the way through
would be a good solution. That's the kind of monitoring I've built in the
past.

(50% might sound like it's near the limit, but the table is growing with an
exponential curve, even quite shallow, it's quite close in terms of time.)

I’m really not sure how we would do that: wouldn’t it require a pretty big
> refactor? It would definitely be cleaner.


Yeah I haven't thought it through. Given the small size of your patch and
the lack of expectation for any similar changes, I think special casing the
migrations framework is a fair tradeoff.

On Wed, 17 Jun 2020 at 13:51, Tom Forbes  wrote:

> I think we should re-open ticket 31007[1] as there was a consensus in 2017
> during the previous attempt at this[2] and things have not really changed -
> a 32bit primary key is still not a sensible default given the calamity that
> can occur when you hit the end of it’s range.
>
> The sticky point is the implementation - how do we migrate new projects
> whilst minimising disruption to existing projects (who either won’t ever
> hit the limit, or have too much data to migrate wholesale). I think special
> casing the migrations framework is an avenue to explore, so I created this
> today and to my surprise it seems to work quite well:
> https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839
> .
>
> The obvious effect of this is that for old projects the Django model
> thinks its primary key is 64 bit while the underlying table is only 32 bit.
> I can’t think of much practical impact of this approach:
> - Python 3 doesn’t distinguish between 32/64 bit numbers so code will
> continue to work as-is.
> - Third party migrations that ship with 32 bit columns won’t be impacted,
> and it’s up to them to create migrations if they want to.
> - Adding `id = BigAutoField(primary_key=True)` to a model will create an
> explicit AlterField migration, when projects are able to migrate.
>
> Am I missing something?
>
> I haven't thought this through, but maybe it's possible to restrict the
> change to inside AutoField, rather than create a new field class. If its
> db_parameters() method / db_type() could receive enough context from the
> migration history, it could potentially determine its own database type.
>
>
> I’m really not sure how we would do that: wouldn’t it require a pretty big
> refactor? It would definitely be cleaner.
>
> 1. https://code.djangoproject.com/ticket/31007
> 2.
> https://groups.google.com/forum/#!msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ
>
>
> On 12 Jun 2020, at 12:11, Adam Johnson  wrote:
>
> I haven't thought this through, but maybe it's possible to restrict the
> change to inside AutoField, rather than create a new field class. If its
> db_parameters() method / db_type() could receive enough context from the
> migration history, it could potentially determine its own database type.
> For those who want to fixed field sizes, BigAutoField and SmallAutoField
> could be left, and MediumAutoField added.
>
> (Whilst poking around I think I spotted a small cleanup:
> https://code.djangoproject.com/ticket/31698 )
>
> On Fri, 12 Jun 2020 at 11:40, Tom Forbes  wrote:
>
>> I think we should restrict the setting between normal and big auto fields
>> only. Allowing UUID's would be changing the type, with the potential for
>> havoc with code incompalities throughout django. It's also not possible to
>> migrate tables over to the new type.
>>
>>
>> That’s a really good point, I got a bit swept up with the idea to realise
>> that it would break a lot of things if applied generally!
>>
>> The autodetector knows if a model is new. It could be that during one
>> version Django outputs BigAutoField for fields added in CreateModel only.
>>
>>
>> We could make every automatic PK become a BigAutoField but include some
>> logic in the migrations framework to *ignore* changes between an
>> auto_created AutoField -> BigAutoField? This would ignore all existing
>> models in your migration history, but all completely new models would
>> receive BigAutoField PKs from the start. Users who explicitly add a
>> `BigAutoField` to a model with a previously created `AutoField` would see a
>> migration created as the `auto_created` flag is not set. It would also play
>>

Re: Defaulting to use BigAutoField in models

2020-06-17 Thread Tom Forbes
I think we should re-open ticket 31007[1] as there was a consensus in 2017 
during the previous attempt at this[2] and things have not really changed - a 
32bit primary key is still not a sensible default given the calamity that can 
occur when you hit the end of it’s range. 

The sticky point is the implementation - how do we migrate new projects whilst 
minimising disruption to existing projects (who either won’t ever hit the 
limit, or have too much data to migrate wholesale). I think special casing the 
migrations framework is an avenue to explore, so I created this today and to my 
surprise it seems to work quite well: 
https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839 
<https://github.com/orf/django/commit/0a335f208cee1376c25eff55c6f866de122c7839>.

The obvious effect of this is that for old projects the Django model thinks its 
primary key is 64 bit while the underlying table is only 32 bit. I can’t think 
of much practical impact of this approach: 
- Python 3 doesn’t distinguish between 32/64 bit numbers so code will continue 
to work as-is. 
- Third party migrations that ship with 32 bit columns won’t be impacted, and 
it’s up to them to create migrations if they want to. 
- Adding `id = BigAutoField(primary_key=True)` to a model will create an 
explicit AlterField migration, when projects are able to migrate.

Am I missing something?

> I haven't thought this through, but maybe it's possible to restrict the 
> change to inside AutoField, rather than create a new field class. If its 
> db_parameters() method / db_type() could receive enough context from the 
> migration history, it could potentially determine its own database type.

I’m really not sure how we would do that: wouldn’t it require a pretty big 
refactor? It would definitely be cleaner.

1. https://code.djangoproject.com/ticket/31007 
<https://code.djangoproject.com/ticket/31007>
2. 
https://groups.google.com/forum/#!msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ
 
<https://groups.google.com/forum/#!msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ>


> On 12 Jun 2020, at 12:11, Adam Johnson  wrote:
> 
> I haven't thought this through, but maybe it's possible to restrict the 
> change to inside AutoField, rather than create a new field class. If its 
> db_parameters() method / db_type() could receive enough context from the 
> migration history, it could potentially determine its own database type. For 
> those who want to fixed field sizes, BigAutoField and SmallAutoField could be 
> left, and MediumAutoField added.
> 
> (Whilst poking around I think I spotted a small cleanup: 
> https://code.djangoproject.com/ticket/31698 
> <https://code.djangoproject.com/ticket/31698> )
> 
> On Fri, 12 Jun 2020 at 11:40, Tom Forbes  <mailto:t...@tomforb.es>> wrote:
>> I think we should restrict the setting between normal and big auto fields 
>> only. Allowing UUID's would be changing the type, with the potential for 
>> havoc with code incompalities throughout django. It's also not possible to 
>> migrate tables over to the new type.
> 
> That’s a really good point, I got a bit swept up with the idea to realise 
> that it would break a lot of things if applied generally!
> 
>> The autodetector knows if a model is new. It could be that during one 
>> version Django outputs BigAutoField for fields added in CreateModel only.
> 
> We could make every automatic PK become a BigAutoField but include some logic 
> in the migrations framework to ignore changes between an auto_created 
> AutoField -> BigAutoField? This would ignore all existing models in your 
> migration history, but all completely new models would receive BigAutoField 
> PKs from the start. Users who explicitly add a `BigAutoField` to a model with 
> a previously created `AutoField` would see a migration created as the 
> `auto_created` flag is not set. It would also play nicely with foreign keys 
> which also need to be 8 bytes.
> 
> This would take care of third party apps with migrations and not require a 
> setting but the downside is that model state will be slightly different from 
> the database. All models would have `BigAutoField`’s whereas the database 
> would only have an `AutoField`. This feels slightly iffy to me even though I 
> cannot think of a case where it would have any practical effect.
> 
>> On 11 Jun 2020, at 19:22, Adam Johnson > <mailto:m...@adamj.eu>> wrote:
>> 
>> Big +1 on solving this from me.
>> 
>> - The setting would take any dotted path to a class, or a single class name 
>> for a build in field. This would potentially solve [3], and could be useful 
>> to people who want to default to other fields like UUIDs (or a custom 
>> BigAutoField) for whatever reason
>> 
>> I think we 

Re: Defaulting to use BigAutoField in models

2020-06-12 Thread Adam Johnson
I haven't thought this through, but maybe it's possible to restrict the
change to inside AutoField, rather than create a new field class. If its
db_parameters() method / db_type() could receive enough context from the
migration history, it could potentially determine its own database type.
For those who want to fixed field sizes, BigAutoField and SmallAutoField
could be left, and MediumAutoField added.

(Whilst poking around I think I spotted a small cleanup:
https://code.djangoproject.com/ticket/31698 )

On Fri, 12 Jun 2020 at 11:40, Tom Forbes  wrote:

> I think we should restrict the setting between normal and big auto fields
> only. Allowing UUID's would be changing the type, with the potential for
> havoc with code incompalities throughout django. It's also not possible to
> migrate tables over to the new type.
>
>
> That’s a really good point, I got a bit swept up with the idea to realise
> that it would break a lot of things if applied generally!
>
> The autodetector knows if a model is new. It could be that during one
> version Django outputs BigAutoField for fields added in CreateModel only.
>
>
> We could make every automatic PK become a BigAutoField but include some
> logic in the migrations framework to *ignore* changes between an
> auto_created AutoField -> BigAutoField? This would ignore all existing
> models in your migration history, but all completely new models would
> receive BigAutoField PKs from the start. Users who explicitly add a
> `BigAutoField` to a model with a previously created `AutoField` would see a
> migration created as the `auto_created` flag is not set. It would also play
> nicely with foreign keys which also need to be 8 bytes.
>
> This would take care of third party apps with migrations and not require a
> setting but the downside is that model state will be slightly different
> from the database. All models would have `BigAutoField`’s whereas the
> database would only have an `AutoField`. This feels slightly iffy to me
> even though I cannot think of a case where it would have any practical
> effect.
>
> On 11 Jun 2020, at 19:22, Adam Johnson  wrote:
>
> Big +1 on solving this from me.
>
> - The setting would take any dotted path to a class, or a single class
>> name for a build in field. This would potentially solve [3], and could be
>> useful to people who want to default to other fields like UUIDs (or a
>> custom BigAutoField) for whatever reason
>>
>
> I think we should restrict the setting between normal and big auto fields
> only. Allowing UUID's would be changing the type, with the potential for
> havoc with code incompalities throughout django. It's also not possible to
> migrate tables over to the new type.
>
> What do you think the solution is for third-party apps? They ship their
> own migrations and can't really be tied to project state.
>
> As Django migrations are derived from the current model state so there’s
>> no way I can think of to express “make this auto-generated field a
>> BigAutoField only if this model is *new*”.
>>
>
> The autodetector knows if a model is new. It could be that during one
> version Django outputs BigAutoField for fields added in CreateModel only.
>
> On Thu, 11 Jun 2020 at 16:28, Tom Forbes  wrote:
>
>> I’d like to re-propose switching Django to use BigAutoField’s rather than
>> the current AutoField. This has been proposed[1] before (and a MR made[2])
>> but it was closed due to implementation issues and not much else has
>> happened since then.
>>
>> As many of you are aware the max value a standard AutoField can hold is
>> 2,147,483,647 (2.1 billion) which sounds like more than you can ever need.
>> But it’s often not, and you only find out at the worst possible time - out
>> of the blue at night and during a period of rapid growth. The process for
>> fixing this issue also becomes a lot harder as your data grows - when
>> you’ve hit the limit you’re looking at a multi-hour `ALTER TABLE` on
>> Postgres during which writes and reads are blocked, or a risky operation to
>> create a new table with the correct primary key and copy old data over in
>> batches. Basically if you’ve experienced this before you wouldn’t wish it
>> on your worst enemy.
>>
>> I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements
>> welcome!) setting that _defaults_ to `BigAutoField`, with prominent
>> docs/release notes saying that to preserve the existing behaviour this
>> should be set to `AutoField`. I think this the only realistic way we can
>> implement this for new projects in a way that ensures it will be used
>> meaningfully and not forgotten about until it’s too late.
>>
>> Rails managed to 

Re: Defaulting to use BigAutoField in models

2020-06-12 Thread Tom Forbes
> I think we should restrict the setting between normal and big auto fields 
> only. Allowing UUID's would be changing the type, with the potential for 
> havoc with code incompalities throughout django. It's also not possible to 
> migrate tables over to the new type.

That’s a really good point, I got a bit swept up with the idea to realise that 
it would break a lot of things if applied generally!

> The autodetector knows if a model is new. It could be that during one version 
> Django outputs BigAutoField for fields added in CreateModel only.

We could make every automatic PK become a BigAutoField but include some logic 
in the migrations framework to ignore changes between an auto_created AutoField 
-> BigAutoField? This would ignore all existing models in your migration 
history, but all completely new models would receive BigAutoField PKs from the 
start. Users who explicitly add a `BigAutoField` to a model with a previously 
created `AutoField` would see a migration created as the `auto_created` flag is 
not set. It would also play nicely with foreign keys which also need to be 8 
bytes.

This would take care of third party apps with migrations and not require a 
setting but the downside is that model state will be slightly different from 
the database. All models would have `BigAutoField`’s whereas the database would 
only have an `AutoField`. This feels slightly iffy to me even though I cannot 
think of a case where it would have any practical effect.

> On 11 Jun 2020, at 19:22, Adam Johnson  wrote:
> 
> Big +1 on solving this from me.
> 
> - The setting would take any dotted path to a class, or a single class name 
> for a build in field. This would potentially solve [3], and could be useful 
> to people who want to default to other fields like UUIDs (or a custom 
> BigAutoField) for whatever reason
> 
> I think we should restrict the setting between normal and big auto fields 
> only. Allowing UUID's would be changing the type, with the potential for 
> havoc with code incompalities throughout django. It's also not possible to 
> migrate tables over to the new type.
> 
> What do you think the solution is for third-party apps? They ship their own 
> migrations and can't really be tied to project state.
> 
> As Django migrations are derived from the current model state so there’s no 
> way I can think of to express “make this auto-generated field a BigAutoField 
> only if this model is new”.
> 
> The autodetector knows if a model is new. It could be that during one version 
> Django outputs BigAutoField for fields added in CreateModel only.
> 
> On Thu, 11 Jun 2020 at 16:28, Tom Forbes  <mailto:t...@tomforb.es>> wrote:
> I’d like to re-propose switching Django to use BigAutoField’s rather than the 
> current AutoField. This has been proposed[1] before (and a MR made[2]) but it 
> was closed due to implementation issues and not much else has happened since 
> then.
> 
> As many of you are aware the max value a standard AutoField can hold is 
> 2,147,483,647 (2.1 billion) which sounds like more than you can ever need. 
> But it’s often not, and you only find out at the worst possible time - out of 
> the blue at night and during a period of rapid growth. The process for fixing 
> this issue also becomes a lot harder as your data grows - when you’ve hit the 
> limit you’re looking at a multi-hour `ALTER TABLE` on Postgres during which 
> writes and reads are blocked, or a risky operation to create a new table with 
> the correct primary key and copy old data over in batches. Basically if 
> you’ve experienced this before you wouldn’t wish it on your worst enemy.
> 
> I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements welcome!) 
> setting that _defaults_ to `BigAutoField`, with prominent docs/release notes 
> saying that to preserve the existing behaviour this should be set to 
> `AutoField`. I think this the only realistic way we can implement this for 
> new projects in a way that ensures it will be used meaningfully and not 
> forgotten about until it’s too late.
> 
> Rails managed to do this migration somewhat painlessly due the big 
> differences between Rails and Django models. As Django migrations are derived 
> from the current model state so there’s no way I can think of to express 
> “make this auto-generated field a BigAutoField only if this model is new”. 
> The way I see it is that a global setting is very easy to toggle and there is 
> little chance of missing the large numbers of migrations that would be 
> generated during the Django update. Smaller applications could apply the 
> migrations with little issue and larger applications would be able to opt-out 
> (as well as be reminded that this is a problem they could face!).
> 
> Some specifics:
> - The s

Re: Defaulting to use BigAutoField in models

2020-06-11 Thread Adam Johnson
Big +1 on solving this from me.

- The setting would take any dotted path to a class, or a single class name
> for a build in field. This would potentially solve [3], and could be useful
> to people who want to default to other fields like UUIDs (or a custom
> BigAutoField) for whatever reason
>

I think we should restrict the setting between normal and big auto fields
only. Allowing UUID's would be changing the type, with the potential for
havoc with code incompalities throughout django. It's also not possible to
migrate tables over to the new type.

What do you think the solution is for third-party apps? They ship their own
migrations and can't really be tied to project state.

As Django migrations are derived from the current model state so there’s no
> way I can think of to express “make this auto-generated field a
> BigAutoField only if this model is *new*”.
>

The autodetector knows if a model is new. It could be that during one
version Django outputs BigAutoField for fields added in CreateModel only.

On Thu, 11 Jun 2020 at 16:28, Tom Forbes  wrote:

> I’d like to re-propose switching Django to use BigAutoField’s rather than
> the current AutoField. This has been proposed[1] before (and a MR made[2])
> but it was closed due to implementation issues and not much else has
> happened since then.
>
> As many of you are aware the max value a standard AutoField can hold is
> 2,147,483,647 (2.1 billion) which sounds like more than you can ever need.
> But it’s often not, and you only find out at the worst possible time - out
> of the blue at night and during a period of rapid growth. The process for
> fixing this issue also becomes a lot harder as your data grows - when
> you’ve hit the limit you’re looking at a multi-hour `ALTER TABLE` on
> Postgres during which writes and reads are blocked, or a risky operation to
> create a new table with the correct primary key and copy old data over in
> batches. Basically if you’ve experienced this before you wouldn’t wish it
> on your worst enemy.
>
> I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements
> welcome!) setting that _defaults_ to `BigAutoField`, with prominent
> docs/release notes saying that to preserve the existing behaviour this
> should be set to `AutoField`. I think this the only realistic way we can
> implement this for new projects in a way that ensures it will be used
> meaningfully and not forgotten about until it’s too late.
>
> Rails managed to do this migration somewhat painlessly due the big
> differences between Rails and Django models. As Django migrations are
> derived from the current model state so there’s no way I can think of to
> express “make this auto-generated field a BigAutoField only if this model
> is *new*”. The way I see it is that a global setting is very easy to
> toggle and there is little chance of missing the large numbers of
> migrations that would be generated during the Django update. Smaller
> applications could apply the migrations with little issue and larger
> applications would be able to opt-out (as well as be reminded that this is
> a problem they could face!).
>
> Some specifics:
> - The setting would take any dotted path to a class, or a single class
> name for a build in field. This would potentially solve [3], and could be
> useful to people who want to default to other fields like UUIDs (or a
> custom BigAutoField) for whatever reason
> - The setting would also be used for GenericForeignKeys, which right now
> are backed by a PositiveIntegerField and so suffer from the same AutoField
> limitations
>
> Any thoughts on this?
>
> Tom
>
> 1.
> https://groups.google.com/d/msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ
>
> 2. https://github.com/django/django/pull/8924/
>
> 3. https://code.djangoproject.com/ticket/56
> <https://groups.google.com/d/msg/django-developers/VFXZpHnuEJc/bbefjX9yCQAJ>
>
>
>
> --
> 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 django-developers+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/django-developers/435EC704-3EF6-4EF4-BF85-175AE29C01F5%40tomforb.es
> <https://groups.google.com/d/msgid/django-developers/435EC704-3EF6-4EF4-BF85-175AE29C01F5%40tomforb.es?utm_medium=email_source=footer>
> .
>


-- 
Adam

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/CAMyDDM1EbbffnydYkVZELcvX3d5y%3DprOCi-b0naYDsP0PRSOwA%40mail.gmail.com.


Re: Defaulting to use BigAutoField in models

2020-06-11 Thread Caio Ariede
For the record, there was a related discussion a few months ago:

https://groups.google.com/d/msg/django-developers/VFXZpHnuEJc/bbefjX9yCQAJ


> On 11 Jun 2020, at 12:28, Tom Forbes  wrote:
> 
> nsures it will be used meaningfully and not forgotten about until it’s too 
> late.
> 

-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/4F05621B-F004-44B5-901E-29962D531804%40gmail.com.


Defaulting to use BigAutoField in models

2020-06-11 Thread Tom Forbes
I’d like to re-propose switching Django to use BigAutoField’s rather than the 
current AutoField. This has been proposed[1] before (and a MR made[2]) but it 
was closed due to implementation issues and not much else has happened since 
then.

As many of you are aware the max value a standard AutoField can hold is 
2,147,483,647 (2.1 billion) which sounds like more than you can ever need. But 
it’s often not, and you only find out at the worst possible time - out of the 
blue at night and during a period of rapid growth. The process for fixing this 
issue also becomes a lot harder as your data grows - when you’ve hit the limit 
you’re looking at a multi-hour `ALTER TABLE` on Postgres during which writes 
and reads are blocked, or a risky operation to create a new table with the 
correct primary key and copy old data over in batches. Basically if you’ve 
experienced this before you wouldn’t wish it on your worst enemy.

I’m proposing that we add a `MODELS_PRIMARY_KEY` (name improvements welcome!) 
setting that _defaults_ to `BigAutoField`, with prominent docs/release notes 
saying that to preserve the existing behaviour this should be set to 
`AutoField`. I think this the only realistic way we can implement this for new 
projects in a way that ensures it will be used meaningfully and not forgotten 
about until it’s too late.

Rails managed to do this migration somewhat painlessly due the big differences 
between Rails and Django models. As Django migrations are derived from the 
current model state so there’s no way I can think of to express “make this 
auto-generated field a BigAutoField only if this model is new”. The way I see 
it is that a global setting is very easy to toggle and there is little chance 
of missing the large numbers of migrations that would be generated during the 
Django update. Smaller applications could apply the migrations with little 
issue and larger applications would be able to opt-out (as well as be reminded 
that this is a problem they could face!).

Some specifics:
- The setting would take any dotted path to a class, or a single class name for 
a build in field. This would potentially solve [3], and could be useful to 
people who want to default to other fields like UUIDs (or a custom 
BigAutoField) for whatever reason
- The setting would also be used for GenericForeignKeys, which right now are 
backed by a PositiveIntegerField and so suffer from the same AutoField 
limitations

Any thoughts on this?

Tom

1. https://groups.google.com/d/msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ 
<https://groups.google.com/d/msg/django-developers/imBJwRrtJkk/P4g0Y87lAgAJ>

2. https://github.com/django/django/pull/8924/ 
<https://github.com/django/django/pull/8924/>

3. https://code.djangoproject.com/ticket/56 
<https://groups.google.com/d/msg/django-developers/VFXZpHnuEJc/bbefjX9yCQAJ>



-- 
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 django-developers+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-developers/435EC704-3EF6-4EF4-BF85-175AE29C01F5%40tomforb.es.


Re: Default to BigAutoField

2017-08-31 Thread Adam Johnson
I agree with Tim. I also think the rename has potential to mess with
historical migrations, or other uses of the field classes, since the output
of deconstruct() will change the class name.

On 31 August 2017 at 16:13, Tim Graham <timogra...@gmail.com> wrote:

> Glancing at the PR, one thing I'm not sure about is renaming AutoField to
> SmallAutoField. I think that's going to cause needless additional
> complexity and confusion among people who've worked with Django a long
> time. For example, you might think that "Small" there has a similar meaning
> as SmallIntegerField. Did I miss the discussion about the benefits of the
> rename? If we agree to proceed with it, please split it out into a separate
> ticket/PR for easier review.
>
> On Sunday, August 27, 2017 at 5:31:47 AM UTC-4, Adam Johnson wrote:
>>
>> I don't think "primary key size" is something that's even within
>> consideration for 99% of django apps. Sure a few more bytes are going to be
>> wasted here, but you could argue the same that the default AutoField was
>> already too big for most models that have 100's of instances and could use
>> even a one byte primary key.
>>
>> Defaulting to BigAutoField everywhere is the simple solution that stops
>> everyone from ever worrying about their tables filling up. Additionally
>> using compressed tables helps reclaim nearly all those unused bytes, at
>> least on MySQL.
>>
>> On 18 August 2017 at 17:14, Andrew Godwin <and...@aeracode.org> wrote:
>>
>>>
>>>
>>> On Fri, Aug 18, 2017 at 5:43 AM, Markus Holtermann <
>>> in...@markusholtermann.eu> wrote:
>>>>
>>>> I'm don't fully agree with the approach. This essentially forces 3rd
>>>> party package authors to make the call about the primary key field size.
>>>> While for small to medium size projects BigAutoField is unlikely
>>>> required and only comes with additional (storage) costs. Given that the
>>>> migrations would need to be part of the 3rd party package there's also
>>>> no (trivial) way for project developers to force or change to
>>>> SmallAutoField for those packages. The same thing holds the other way
>>>> round.
>>>>
>>>> Unfortunately, I don't have another solution at hand.
>>>>
>>>>
>>> This is also true of changing the primary key of third-party packages in
>>> general though - e.g. there's no way I can make everything use UUIDs even
>>> if my database would be way better at those.
>>>
>>> I don't see any other solutions that aren't settings doing
>>> spooky-action-at-a-distance to primary keys, and that's something I really
>>> don't want to see.
>>>
>>> Andrew
>>>
>>>
>>>>
>>>> On Thu, Aug 17, 2017 at 02:43:07PM -0700, Andrew Godwin wrote:
>>>>
>>>>> To elaborate on the solution we eventually came up with - we default
>>>>> models
>>>>> to use a new BigAutoField that migrations will pick up on and generate
>>>>> migrations to alter columns to, but for safety reasons for those that
>>>>> don't
>>>>> read release notes, made the migration autodetector ask you if you
>>>>> want to
>>>>> make these migrations with a slowness warning.
>>>>>
>>>>> It also tells you how to preserve the old behaviour and avoid new
>>>>> migrations if you wish (manually set id = SmallAutoField)
>>>>>
>>>>> I like this approach as it means no new settings or Meta options or
>>>>> anything, has a reasonable upgrade path, and won't let people
>>>>> unwittingly
>>>>> wander into giant changes. The downside is that it does add slightly
>>>>> more
>>>>> friction to the upgrade process.
>>>>>
>>>>> Andrew
>>>>>
>>>>> On Thu, Aug 17, 2017 at 2:36 PM, Kenneth Reitz <m...@kennethreitz.org>
>>>>> wrote:
>>>>>
>>>>> I have opened a pull request:
>>>>>>
>>>>>> https://github.com/django/django/pull/8924
>>>>>>
>>>>>> Andrew and I came up with a good solution for migrations, together at
>>>>>> DjangoCon.
>>>>>>
>>>>>> On Wednesday, June 14, 2017 at 7:36:36 AM UTC-7, Melvyn Sopacua wrote:
>>>>>>
>>>>>>>
>>>>>>> On Friday 09 June 2017 15:59:50 Kenne

Re: Default to BigAutoField

2017-08-31 Thread Tim Graham
Glancing at the PR, one thing I'm not sure about is renaming AutoField to 
SmallAutoField. I think that's going to cause needless additional 
complexity and confusion among people who've worked with Django a long 
time. For example, you might think that "Small" there has a similar meaning 
as SmallIntegerField. Did I miss the discussion about the benefits of the 
rename? If we agree to proceed with it, please split it out into a separate 
ticket/PR for easier review.

On Sunday, August 27, 2017 at 5:31:47 AM UTC-4, Adam Johnson wrote:
>
> I don't think "primary key size" is something that's even within 
> consideration for 99% of django apps. Sure a few more bytes are going to be 
> wasted here, but you could argue the same that the default AutoField was 
> already too big for most models that have 100's of instances and could use 
> even a one byte primary key.
>
> Defaulting to BigAutoField everywhere is the simple solution that stops 
> everyone from ever worrying about their tables filling up. Additionally 
> using compressed tables helps reclaim nearly all those unused bytes, at 
> least on MySQL.
>
> On 18 August 2017 at 17:14, Andrew Godwin <and...@aeracode.org 
> > wrote:
>
>>
>>
>> On Fri, Aug 18, 2017 at 5:43 AM, Markus Holtermann <
>> in...@markusholtermann.eu > wrote:
>>>
>>> I'm don't fully agree with the approach. This essentially forces 3rd
>>> party package authors to make the call about the primary key field size.
>>> While for small to medium size projects BigAutoField is unlikely
>>> required and only comes with additional (storage) costs. Given that the
>>> migrations would need to be part of the 3rd party package there's also
>>> no (trivial) way for project developers to force or change to
>>> SmallAutoField for those packages. The same thing holds the other way
>>> round.
>>>
>>> Unfortunately, I don't have another solution at hand.
>>>
>>>
>> This is also true of changing the primary key of third-party packages in 
>> general though - e.g. there's no way I can make everything use UUIDs even 
>> if my database would be way better at those.
>>
>> I don't see any other solutions that aren't settings doing 
>> spooky-action-at-a-distance to primary keys, and that's something I really 
>> don't want to see.
>>
>> Andrew
>>  
>>
>>>
>>> On Thu, Aug 17, 2017 at 02:43:07PM -0700, Andrew Godwin wrote:
>>>
>>>> To elaborate on the solution we eventually came up with - we default 
>>>> models
>>>> to use a new BigAutoField that migrations will pick up on and generate
>>>> migrations to alter columns to, but for safety reasons for those that 
>>>> don't
>>>> read release notes, made the migration autodetector ask you if you want 
>>>> to
>>>> make these migrations with a slowness warning.
>>>>
>>>> It also tells you how to preserve the old behaviour and avoid new
>>>> migrations if you wish (manually set id = SmallAutoField)
>>>>
>>>> I like this approach as it means no new settings or Meta options or
>>>> anything, has a reasonable upgrade path, and won't let people 
>>>> unwittingly
>>>> wander into giant changes. The downside is that it does add slightly 
>>>> more
>>>> friction to the upgrade process.
>>>>
>>>> Andrew
>>>>
>>>> On Thu, Aug 17, 2017 at 2:36 PM, Kenneth Reitz <m...@kennethreitz.org 
>>>> > wrote:
>>>>
>>>> I have opened a pull request:
>>>>>
>>>>> https://github.com/django/django/pull/8924
>>>>>
>>>>> Andrew and I came up with a good solution for migrations, together at
>>>>> DjangoCon.
>>>>>
>>>>> On Wednesday, June 14, 2017 at 7:36:36 AM UTC-7, Melvyn Sopacua wrote:
>>>>>
>>>>>>
>>>>>> On Friday 09 June 2017 15:59:50 Kenneth Reitz wrote:
>>>>>>
>>>>>> > However, it should also be noted that those same larger applications
>>>>>>
>>>>>> > are the ones that are likely to run into this problem eventually, so
>>>>>>
>>>>>> > perhaps forcing the migration is the best path moving forward.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Existing models are the problem. Then again the database knows the 
>

Re: Default to BigAutoField

2017-08-27 Thread Adam Johnson
I don't think "primary key size" is something that's even within
consideration for 99% of django apps. Sure a few more bytes are going to be
wasted here, but you could argue the same that the default AutoField was
already too big for most models that have 100's of instances and could use
even a one byte primary key.

Defaulting to BigAutoField everywhere is the simple solution that stops
everyone from ever worrying about their tables filling up. Additionally
using compressed tables helps reclaim nearly all those unused bytes, at
least on MySQL.

On 18 August 2017 at 17:14, Andrew Godwin <and...@aeracode.org> wrote:

>
>
> On Fri, Aug 18, 2017 at 5:43 AM, Markus Holtermann <
> i...@markusholtermann.eu> wrote:
>>
>> I'm don't fully agree with the approach. This essentially forces 3rd
>> party package authors to make the call about the primary key field size.
>> While for small to medium size projects BigAutoField is unlikely
>> required and only comes with additional (storage) costs. Given that the
>> migrations would need to be part of the 3rd party package there's also
>> no (trivial) way for project developers to force or change to
>> SmallAutoField for those packages. The same thing holds the other way
>> round.
>>
>> Unfortunately, I don't have another solution at hand.
>>
>>
> This is also true of changing the primary key of third-party packages in
> general though - e.g. there's no way I can make everything use UUIDs even
> if my database would be way better at those.
>
> I don't see any other solutions that aren't settings doing
> spooky-action-at-a-distance to primary keys, and that's something I really
> don't want to see.
>
> Andrew
>
>
>>
>> On Thu, Aug 17, 2017 at 02:43:07PM -0700, Andrew Godwin wrote:
>>
>>> To elaborate on the solution we eventually came up with - we default
>>> models
>>> to use a new BigAutoField that migrations will pick up on and generate
>>> migrations to alter columns to, but for safety reasons for those that
>>> don't
>>> read release notes, made the migration autodetector ask you if you want
>>> to
>>> make these migrations with a slowness warning.
>>>
>>> It also tells you how to preserve the old behaviour and avoid new
>>> migrations if you wish (manually set id = SmallAutoField)
>>>
>>> I like this approach as it means no new settings or Meta options or
>>> anything, has a reasonable upgrade path, and won't let people unwittingly
>>> wander into giant changes. The downside is that it does add slightly more
>>> friction to the upgrade process.
>>>
>>> Andrew
>>>
>>> On Thu, Aug 17, 2017 at 2:36 PM, Kenneth Reitz <m...@kennethreitz.org>
>>> wrote:
>>>
>>> I have opened a pull request:
>>>>
>>>> https://github.com/django/django/pull/8924
>>>>
>>>> Andrew and I came up with a good solution for migrations, together at
>>>> DjangoCon.
>>>>
>>>> On Wednesday, June 14, 2017 at 7:36:36 AM UTC-7, Melvyn Sopacua wrote:
>>>>
>>>>>
>>>>> On Friday 09 June 2017 15:59:50 Kenneth Reitz wrote:
>>>>>
>>>>> > However, it should also be noted that those same larger applications
>>>>>
>>>>> > are the ones that are likely to run into this problem eventually, so
>>>>>
>>>>> > perhaps forcing the migration is the best path moving forward.
>>>>>
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> Existing models are the problem. Then again the database knows the
>>>>> truth.
>>>>> So with a little inspection during apps.get_models we might be able to
>>>>> do
>>>>> the right thing and even allow migrating in steps.
>>>>>
>>>>>
>>>>>
>>>>> Apps is also the place to mark an app as migrated.
>>>>>
>>>>>
>>>>>
>>>>> In fact - couldn't an AppConfig grow a method "get_autoid_type()" and
>>>>> inject the right one?
>>>>>
>>>>>
>>>>>
>>>>> You asked fr thoughts, so there's my 2c stream.
>>>>>
>>>>> --
>>>>>
>>>>> Melvyn Sopacua
>>>>>
>>>>> --
>>>> You received this message because you are subscribed to the Google
>>>> Groups
>>>> "Django develope

Re: Default to BigAutoField

2017-08-18 Thread Andrew Godwin
On Fri, Aug 18, 2017 at 5:43 AM, Markus Holtermann <i...@markusholtermann.eu
> wrote:
>
> I'm don't fully agree with the approach. This essentially forces 3rd
> party package authors to make the call about the primary key field size.
> While for small to medium size projects BigAutoField is unlikely
> required and only comes with additional (storage) costs. Given that the
> migrations would need to be part of the 3rd party package there's also
> no (trivial) way for project developers to force or change to
> SmallAutoField for those packages. The same thing holds the other way
> round.
>
> Unfortunately, I don't have another solution at hand.
>
>
This is also true of changing the primary key of third-party packages in
general though - e.g. there's no way I can make everything use UUIDs even
if my database would be way better at those.

I don't see any other solutions that aren't settings doing
spooky-action-at-a-distance to primary keys, and that's something I really
don't want to see.

Andrew


>
> On Thu, Aug 17, 2017 at 02:43:07PM -0700, Andrew Godwin wrote:
>
>> To elaborate on the solution we eventually came up with - we default
>> models
>> to use a new BigAutoField that migrations will pick up on and generate
>> migrations to alter columns to, but for safety reasons for those that
>> don't
>> read release notes, made the migration autodetector ask you if you want to
>> make these migrations with a slowness warning.
>>
>> It also tells you how to preserve the old behaviour and avoid new
>> migrations if you wish (manually set id = SmallAutoField)
>>
>> I like this approach as it means no new settings or Meta options or
>> anything, has a reasonable upgrade path, and won't let people unwittingly
>> wander into giant changes. The downside is that it does add slightly more
>> friction to the upgrade process.
>>
>> Andrew
>>
>> On Thu, Aug 17, 2017 at 2:36 PM, Kenneth Reitz <m...@kennethreitz.org>
>> wrote:
>>
>> I have opened a pull request:
>>>
>>> https://github.com/django/django/pull/8924
>>>
>>> Andrew and I came up with a good solution for migrations, together at
>>> DjangoCon.
>>>
>>> On Wednesday, June 14, 2017 at 7:36:36 AM UTC-7, Melvyn Sopacua wrote:
>>>
>>>>
>>>> On Friday 09 June 2017 15:59:50 Kenneth Reitz wrote:
>>>>
>>>> > However, it should also be noted that those same larger applications
>>>>
>>>> > are the ones that are likely to run into this problem eventually, so
>>>>
>>>> > perhaps forcing the migration is the best path moving forward.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Existing models are the problem. Then again the database knows the
>>>> truth.
>>>> So with a little inspection during apps.get_models we might be able to
>>>> do
>>>> the right thing and even allow migrating in steps.
>>>>
>>>>
>>>>
>>>> Apps is also the place to mark an app as migrated.
>>>>
>>>>
>>>>
>>>> In fact - couldn't an AppConfig grow a method "get_autoid_type()" and
>>>> inject the right one?
>>>>
>>>>
>>>>
>>>> You asked fr thoughts, so there's my 2c stream.
>>>>
>>>> --
>>>>
>>>> Melvyn Sopacua
>>>>
>>>> --
>>> 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 django-developers+unsubscr...@googlegroups.com.
>>> To post to this group, send email to django-developers@googlegroups.com.
>>> 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/e3effc41-10e1-42e2-9037-
>>> 84c98217cd91%40googlegroups.com
>>> <https://groups.google.com/d/msgid/django-developers/e3effc4
>>> 1-10e1-42e2-9037-84c98217cd91%40googlegroups.com?utm_medium=
>>> email_source=footer>
>>> .
>>>
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>>
>> --
>> You received this message because you are subscribed to the Google Groups
>> "Django developers  (Contributions to Django itself)" group.
>> To unsubscribe

Re: Default to BigAutoField

2017-08-18 Thread Markus Holtermann

Thanks for taking the effort to work on this, Kenneth!

I'm don't fully agree with the approach. This essentially forces 3rd
party package authors to make the call about the primary key field size.
While for small to medium size projects BigAutoField is unlikely
required and only comes with additional (storage) costs. Given that the
migrations would need to be part of the 3rd party package there's also
no (trivial) way for project developers to force or change to
SmallAutoField for those packages. The same thing holds the other way
round.

Unfortunately, I don't have another solution at hand.

I realized that I'm a bit late to the discussion and should've chimed
in before all that work was done. Please accept my apologies for that.

/Markus


On Thu, Aug 17, 2017 at 02:43:07PM -0700, Andrew Godwin wrote:

To elaborate on the solution we eventually came up with - we default models
to use a new BigAutoField that migrations will pick up on and generate
migrations to alter columns to, but for safety reasons for those that don't
read release notes, made the migration autodetector ask you if you want to
make these migrations with a slowness warning.

It also tells you how to preserve the old behaviour and avoid new
migrations if you wish (manually set id = SmallAutoField)

I like this approach as it means no new settings or Meta options or
anything, has a reasonable upgrade path, and won't let people unwittingly
wander into giant changes. The downside is that it does add slightly more
friction to the upgrade process.

Andrew

On Thu, Aug 17, 2017 at 2:36 PM, Kenneth Reitz <m...@kennethreitz.org> wrote:


I have opened a pull request:

https://github.com/django/django/pull/8924

Andrew and I came up with a good solution for migrations, together at
DjangoCon.

On Wednesday, June 14, 2017 at 7:36:36 AM UTC-7, Melvyn Sopacua wrote:


On Friday 09 June 2017 15:59:50 Kenneth Reitz wrote:

> However, it should also be noted that those same larger applications

> are the ones that are likely to run into this problem eventually, so

> perhaps forcing the migration is the best path moving forward.





Existing models are the problem. Then again the database knows the truth.
So with a little inspection during apps.get_models we might be able to do
the right thing and even allow migrating in steps.



Apps is also the place to mark an app as migrated.



In fact - couldn't an AppConfig grow a method "get_autoid_type()" and
inject the right one?



You asked fr thoughts, so there's my 2c stream.

--

Melvyn Sopacua


--
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/e3effc41-10e1-42e2-9037-
84c98217cd91%40googlegroups.com
<https://groups.google.com/d/msgid/django-developers/e3effc41-10e1-42e2-9037-84c98217cd91%40googlegroups.com?utm_medium=email_source=footer>
.

For more options, visit https://groups.google.com/d/optout.



--
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/CAFwN1uo4Y_pWSf3zAe_4R0GGkDqBv1YGus8Q%2BWPPZ%3DZ6FPwdYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


--
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/20170818124354.GA1898%40inel.local.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-08-17 Thread Andrew Godwin
To elaborate on the solution we eventually came up with - we default models
to use a new BigAutoField that migrations will pick up on and generate
migrations to alter columns to, but for safety reasons for those that don't
read release notes, made the migration autodetector ask you if you want to
make these migrations with a slowness warning.

It also tells you how to preserve the old behaviour and avoid new
migrations if you wish (manually set id = SmallAutoField)

I like this approach as it means no new settings or Meta options or
anything, has a reasonable upgrade path, and won't let people unwittingly
wander into giant changes. The downside is that it does add slightly more
friction to the upgrade process.

Andrew

On Thu, Aug 17, 2017 at 2:36 PM, Kenneth Reitz <m...@kennethreitz.org> wrote:

> I have opened a pull request:
>
> https://github.com/django/django/pull/8924
>
> Andrew and I came up with a good solution for migrations, together at
> DjangoCon.
>
> On Wednesday, June 14, 2017 at 7:36:36 AM UTC-7, Melvyn Sopacua wrote:
>>
>> On Friday 09 June 2017 15:59:50 Kenneth Reitz wrote:
>>
>> > However, it should also be noted that those same larger applications
>>
>> > are the ones that are likely to run into this problem eventually, so
>>
>> > perhaps forcing the migration is the best path moving forward.
>>
>>
>>
>>
>>
>> Existing models are the problem. Then again the database knows the truth.
>> So with a little inspection during apps.get_models we might be able to do
>> the right thing and even allow migrating in steps.
>>
>>
>>
>> Apps is also the place to mark an app as migrated.
>>
>>
>>
>> In fact - couldn't an AppConfig grow a method "get_autoid_type()" and
>> inject the right one?
>>
>>
>>
>> You asked fr thoughts, so there's my 2c stream.
>>
>> --
>>
>> Melvyn Sopacua
>>
> --
> 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 django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> 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/e3effc41-10e1-42e2-9037-
> 84c98217cd91%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/e3effc41-10e1-42e2-9037-84c98217cd91%40googlegroups.com?utm_medium=email_source=footer>
> .
>
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/CAFwN1uo4Y_pWSf3zAe_4R0GGkDqBv1YGus8Q%2BWPPZ%3DZ6FPwdYQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-14 Thread Melvyn Sopacua
On Friday 09 June 2017 15:59:50 Kenneth Reitz wrote:
> However, it should also be noted that those same larger applications
> are the ones that are likely to run into this problem eventually, so
> perhaps forcing the migration is the best path moving forward.


Existing models are the problem. Then again the database knows the truth. So 
with a little inspection during apps.get_models we might be able to do the 
right 
thing and even allow migrating in steps.

Apps is also the place to mark an app as migrated.

In fact - couldn't an AppConfig grow a method "get_autoid_type()" and inject 
the right one?

You asked fr thoughts, so there's my 2c stream.
-- 
Melvyn Sopacua

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/8118805.cf4lglgPtt%40devstation.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-12 Thread Ash Christopher
I really like this idea. We created a custom BigAutoField for our systems 
with sharded databases, and fast growing data.

I understand the desire to fix it for new projects moving forward, but this 
smells a little like what happened with custom User models - it was 
introduced for new projects, but there was no clear upgrade/migration path 
for existing projects. 


On Friday, 9 June 2017 15:54:43 UTC-4, Kenneth Reitz wrote:
>
> My initial thought was to just have this apply to *new* Django 
> applications, if that's possible.
>
> Running this migration could take quite some time on some larger apps, and 
> would require a non-trivial amount of time to execute. 
>
> --
> Kenneth Reitz
>
> On Jun 9, 2017, at 3:53 PM, Tom Forbes <t...@tomforb.es > 
> wrote:
>
> How would this work with generic foreign keys as well? Those migrations 
> couldn't be automatic.
>
> On 9 Jun 2017 20:43, "Jacob Kaplan-Moss" <ja...@jacobian.org > 
> wrote:
>
>> I think this would be a good improvement, and I'd like to see it. I've 
>> been bitten by integers overflowing at least twice I can remember in my 
>> career, which is two times too many.
>>
>> However, a major thing we'd have to work out is the upgrade path Consider 
>> a simple model:
>>
>> class Person(Model):
>> name = CharField()
>>
>> In Django 1.11, this actually generates a model with an integer `id` 
>> field. But in we change it, in Django vNext, that `id` field would "turn 
>> into" a bigint magically without the underlying table changes. That'd be 
>> confusing: you'd expect the model to be "fixed" by pugrading to vNext, but 
>> it wouldn't be. I think the migrations engine would detect this as a 
>> migration (?), so perhaps that's the path forward, but it could still be 
>> super-confusing. We've never shipped a release of Django that required a 
>> migration to _all_ your models.
>>
>> Have you thought about what the upgrade path should look like, Kenneth?
>>
>> Jacob
>>
>> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <ken...@heroku.com 
>> > wrote:
>>
>>> Dear Django Dev,
>>>
>>>  
>>> At Heroku, we have the privilege of seeing an extremely broad range of 
>>> customers utilizing tools like Django to build their applications and 
>>> companies. One of the things that we’ve seen customers hit, time and time 
>>> again when using tools like Django, is integer overflows for primary keys. 
>>> Their application starts behaving unpredictably once they reach the 
>>> overflow, not even knowing such a constraint exists, and they often think 
>>> the problem is with their database provider, rather than with their schema. 
>>> Once they realize what is wrong, it’s a relatively trivial fix, but a 
>>> migration can take several hours to complete, which results in unacceptable 
>>> amounts of downtime.
>>>
>>>  
>>> Because of this, Heroku, as a company, would like to encourage bigints 
>>> as a sane reasonable default for primary keys for application models. If 
>>> the Django project agrees with this idea, that would mean that Django would 
>>> provide BigAutoField as the default for ‘id’ instead of AutoField. 
>>>
>>>  
>>> Rails made this change recently 
>>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen 
>>> success in doing so. 
>>>
>>>  
>>> I’m happy to provide the code to do this, but I wanted to discuss it 
>>> here before doing so, to hear what the general consensus was to the 
>>> proposal of such a change. 
>>>
>>>  
>>>
>>>  
>>> Pros:
>>>
>>>- Users of Django, following the docs, won’t accidentally hit the 
>>>int overflow barrier. 
>>>- Encourages best-practices from the beginning. 
>>>- Bigints don’t take up much more storage than ints when using 
>>>Postgres. 
>>>- In-line with other frameworks moving forward on this issue, like 
>>>Rails <http://www.mccartie.com/2016/12/05/rails-5.1.html>.
>>>
>>>  
>>> Cons:
>>>
>>>- Backwards compatibility would need to be considered. 
>>>
>>>  
>>> Why not UUID?
>>>
>>>  
>>> I agree! I love using UUID for my primary keys, and I think a patch to 
>>> Django which provides an AutoUUIDField would be wonderful. However, there 
>>> are a few major drawbacks to making this the new defa

Re: Default to BigAutoField

2017-06-11 Thread emorley
On Saturday, 10 June 2017 10:33:35 UTC+1, Claude Paroz wrote:
>
> Another idea is to leverage the system check framework (--deploy part) to 
> warn when the max id is over 50% of available range.
>

I was about to suggest the same. Seems like something worth doing 
regardless of whether we change the default (since it would help catch 
issues in existing installations who haven't yet migrated).

Ed

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/fe0c7429-e9e9-406f-8701-8ebc550641e3%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Claude Paroz
Le samedi 10 juin 2017 14:25:49 UTC+2, Curtis Maloney a écrit :

> On 10/06/17 22:21, Claude Paroz wrote: 
> > Another idea would be to offer variants of models.Model which models 
> > could inherit from, like models.BigIntModel or models.UUIDModel. 
>
> Ah, well... now you're talking.  But then, you can do this already as an 
> abstract base with TYPE as id... 
>
> class BigIntModel(models.Model): 
>  id = BigAutoField(primary_key=True) 
>  class Meta: 
>  abstract = True 
>

Absolutely! It would only be a convenience thing. The more I think about 
this, the more I think that it might be addressed by better documentation 
(and maybe some convenience shortcuts). 

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/d6cbd561-190e-40b5-8419-aac3e42f66b4%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Curtis Maloney



On 10/06/17 22:21, Claude Paroz wrote:

Le samedi 10 juin 2017 11:40:42 UTC+2, Curtis Maloney a écrit :

Right, hence my point of having a global setting to say "the default
auto-field is ..."



I see, but this conforms to the pattern "use the same id field type for
all models of my project". I'm not sure we should encourage that.


Yeah... naming would be key with "DEFAULT_AUTO_FIELD_TYPE" or whatever...


Another idea would be to offer variants of models.Model which models
could inherit from, like models.BigIntModel or models.UUIDModel.


Ah, well... now you're talking.  But then, you can do this already as an 
abstract base with TYPE as id...


class BigIntModel(models.Model):
id = BigAutoField(primary_key=True)
class Meta:
abstract = True


--
C

--
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/a7da67fb-349a-c77c-8324-32dc16bd0ada%40tinbrain.net.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Claude Paroz
Le samedi 10 juin 2017 11:40:42 UTC+2, Curtis Maloney a écrit :
>
> Right, hence my point of having a global setting to say "the default 
> auto-field is ..." 
>
> This would: 
> a) ...
>

I see, but this conforms to the pattern "use the same id field type for all 
models of my project". I'm not sure we should encourage that.

Another idea would be to offer variants of models.Model which models could 
inherit from, like models.BigIntModel or models.UUIDModel.

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/3904d3f9-2ed8-432a-83c3-3bbac1dacc55%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Tom Forbes
I really like the idea of a global configurable setting. One problem with a
setting is that it's not always changeable, which settings kind of imply
(IMO). Going from int->bigint is always possible, but going backwards may
not be, nor might going from int->guid.

I attempted an int->guid migration on one of our systems and ran into some
migrations and postgres-specific issues. Seems like it might be incredibly
difficult to get a simple toggle setting to work with it, and there are
lots of pitfalls.

A warning to the system check framework could be added to check if the
primary key type is changed and potentially incompatible generic foreign
key columns exist. And in the docs rather than use a plain IntegerField,
just use a field that changes based on the setting.

On 10 Jun 2017 10:41, "Curtis Maloney" <cur...@tinbrain.net> wrote:

f) let MySQL users opt for PositiveBigAutoField if they want...



On 10/06/17 19:40, Curtis Maloney wrote:

> Right, hence my point of having a global setting to say "the default
> auto-field is ..."
>
> This would:
> a) let people continue to use AutoField
> b) let people opt for BigAutoField
> c) let 3rd party projects be agnostic
> d) let people use UUIDField(default=uuid.uuid4)
> e) possibly make it feasible to change mid-stream from AutoField to
> BigAutoField...
>
> --
> C
>
> On 10/06/17 19:33, Claude Paroz wrote:
>
>> I think we should first discuss if it makes sense to set a BigAutoField
>> by default for all tables. I'm not convinced of that yet. I looked at my
>> projects with this perspective and found for example a case where I have
>> many small lookup tables (containing between 2-20 entries) for which I
>> know I would never use BigAutoField if I'd design the schema on paper.
>>
>> For me, it's a bit like the `on_delete` parameter for foreign keys. A no
>> "one size fits all" situation.
>> For example, a quick analysis of contrib models (sorry for bad
>> formatting):
>>
>> Model BigAutoField appropriate
>> ===
>> admin.LogEntry yes
>> auth.Userno
>> auth.Group  no
>> auth.Permission no
>> contenttype.ContentType no
>> flatpage.FlatPage  no
>> redirect.Redirectno
>> sessions.Session  yes
>> sites.Site no
>>
>> Shouldn't we treat that issue by better documentation instead?
>> Another idea is to leverage the system check framework (--deploy part)
>> to warn when the max id is over 50% of available range.
>> We are perfectionists, aren't we :-)
>>
>> Claude
>>
>> --
>> 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 django-developers+unsubscr...@googlegroups.com
>> <mailto:django-developers+unsubscr...@googlegroups.com>.
>> To post to this group, send email to django-developers@googlegroups.com
>> <mailto:django-developers@googlegroups.com>.
>> 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/0fba4c2c
>> -cd56-4c7d-82b9-7be0a7a3d233%40googlegroups.com
>>
>> <https://groups.google.com/d/msgid/django-developers/0fba4c2
>> c-cd56-4c7d-82b9-7be0a7a3d233%40googlegroups.com?utm_medium=
>> email_source=footer>.
>>
>> For more options, visit https://groups.google.com/d/optout.
>>
>
>
-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
Visit this group at https://groups.google.com/group/django-developers.
To view this discussion on the web visit https://groups.google.com/d/ms
gid/django-developers/ec59bb2e-bce9-924f-1509-60709a07c5dc%40tinbrain.net.

For more options, visit https://groups.google.com/d/optout.

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/CAFNZOJMntP93kaJ%2BbPuHzAr2rKqZbbSbu1TRc%2Bm%2Bp-%2BiO%2BojvQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Curtis Maloney

f) let MySQL users opt for PositiveBigAutoField if they want...


On 10/06/17 19:40, Curtis Maloney wrote:

Right, hence my point of having a global setting to say "the default
auto-field is ..."

This would:
a) let people continue to use AutoField
b) let people opt for BigAutoField
c) let 3rd party projects be agnostic
d) let people use UUIDField(default=uuid.uuid4)
e) possibly make it feasible to change mid-stream from AutoField to
BigAutoField...

--
C

On 10/06/17 19:33, Claude Paroz wrote:

I think we should first discuss if it makes sense to set a BigAutoField
by default for all tables. I'm not convinced of that yet. I looked at my
projects with this perspective and found for example a case where I have
many small lookup tables (containing between 2-20 entries) for which I
know I would never use BigAutoField if I'd design the schema on paper.

For me, it's a bit like the `on_delete` parameter for foreign keys. A no
"one size fits all" situation.
For example, a quick analysis of contrib models (sorry for bad
formatting):

Model BigAutoField appropriate
===
admin.LogEntry yes
auth.Userno
auth.Group  no
auth.Permission no
contenttype.ContentType no
flatpage.FlatPage  no
redirect.Redirectno
sessions.Session  yes
sites.Site no

Shouldn't we treat that issue by better documentation instead?
Another idea is to leverage the system check framework (--deploy part)
to warn when the max id is over 50% of available range.
We are perfectionists, aren't we :-)

Claude

--
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 django-developers+unsubscr...@googlegroups.com
<mailto:django-developers+unsubscr...@googlegroups.com>.
To post to this group, send email to django-developers@googlegroups.com
<mailto:django-developers@googlegroups.com>.
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/0fba4c2c-cd56-4c7d-82b9-7be0a7a3d233%40googlegroups.com

<https://groups.google.com/d/msgid/django-developers/0fba4c2c-cd56-4c7d-82b9-7be0a7a3d233%40googlegroups.com?utm_medium=email_source=footer>.

For more options, visit https://groups.google.com/d/optout.




--
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/ec59bb2e-bce9-924f-1509-60709a07c5dc%40tinbrain.net.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Curtis Maloney
Right, hence my point of having a global setting to say "the default 
auto-field is ..."


This would:
a) let people continue to use AutoField
b) let people opt for BigAutoField
c) let 3rd party projects be agnostic
d) let people use UUIDField(default=uuid.uuid4)
e) possibly make it feasible to change mid-stream from AutoField to 
BigAutoField...


--
C

On 10/06/17 19:33, Claude Paroz wrote:

I think we should first discuss if it makes sense to set a BigAutoField
by default for all tables. I'm not convinced of that yet. I looked at my
projects with this perspective and found for example a case where I have
many small lookup tables (containing between 2-20 entries) for which I
know I would never use BigAutoField if I'd design the schema on paper.

For me, it's a bit like the `on_delete` parameter for foreign keys. A no
"one size fits all" situation.
For example, a quick analysis of contrib models (sorry for bad formatting):

Model BigAutoField appropriate
===
admin.LogEntry yes
auth.Userno
auth.Group  no
auth.Permission no
contenttype.ContentType no
flatpage.FlatPage  no
redirect.Redirectno
sessions.Session  yes
sites.Site no

Shouldn't we treat that issue by better documentation instead?
Another idea is to leverage the system check framework (--deploy part)
to warn when the max id is over 50% of available range.
We are perfectionists, aren't we :-)

Claude

--
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 django-developers+unsubscr...@googlegroups.com
<mailto:django-developers+unsubscr...@googlegroups.com>.
To post to this group, send email to django-developers@googlegroups.com
<mailto:django-developers@googlegroups.com>.
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/0fba4c2c-cd56-4c7d-82b9-7be0a7a3d233%40googlegroups.com
<https://groups.google.com/d/msgid/django-developers/0fba4c2c-cd56-4c7d-82b9-7be0a7a3d233%40googlegroups.com?utm_medium=email_source=footer>.
For more options, visit https://groups.google.com/d/optout.


--
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/43c2a63f-87de-fda1-87c3-412574c13804%40tinbrain.net.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Claude Paroz
I think we should first discuss if it makes sense to set a BigAutoField by 
default for all tables. I'm not convinced of that yet. I looked at my 
projects with this perspective and found for example a case where I have 
many small lookup tables (containing between 2-20 entries) for which I know 
I would never use BigAutoField if I'd design the schema on paper.

For me, it's a bit like the `on_delete` parameter for foreign keys. A no 
"one size fits all" situation.
For example, a quick analysis of contrib models (sorry for bad formatting):

Model     BigAutoField appropriate
===
admin.LogEntry yes
auth.Userno
auth.Group  no
auth.Permission no
contenttype.ContentType no
flatpage.FlatPage  no
redirect.Redirectno
sessions.Session  yes
sites.Site no

Shouldn't we treat that issue by better documentation instead?
Another idea is to leverage the system check framework (--deploy part) to 
warn when the max id is over 50% of available range.
We are perfectionists, aren't we :-)

Claude

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/0fba4c2c-cd56-4c7d-82b9-7be0a7a3d233%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: Default to BigAutoField

2017-06-10 Thread Andrew Godwin
As long as you changed the actual field that ended up under the "id"
column, then yes, migrations should detect it and apply all the changes
during an upgrade, including to foreign keys.

Generic foreign keys are another problem, however, not to mention the
prospect of how many migrations and ALTER TABLES this would result in on a
large project. We could include in the upgrade notes how to stave it off
(explicitly specify an ID field), but I'm sort of on the fence as to if
that's good enough.

Andrew

On Sat, Jun 10, 2017 at 9:53 AM, Collin Anderson <cmawebs...@gmail.com>
wrote:

> I might be wrong, but if the default changes, won't the migrations detect
> it and migrate it just fine, including foreign keys?
>
> All of my migrations have this:
> ('id', models.AutoField(auto_created=True, primary_key=True,
> serialize=False, verbose_name='ID')),
>
> So everyone would either need to manually specify the AutoField to keep
> the old behavior, or run makemigrations to auto-generate migrations to
> BigAutoField. This seems similar to increasing the max_length of
> EmailField, user.username, and user.last_name, though would affect a lot
> more models in this case.
>
> (I'm not sure what I think about the setting idea.)
>
> (While we're at it, maybe we could make it a (new) PositiveBigAutoField to
> help out the mysql folks and close the oldest open ticket:
> https://code.djangoproject.com/ticket/56 :)
>
>
>
> On Fri, Jun 9, 2017 at 9:37 PM, Tim Graham <timogra...@gmail.com> wrote:
>
>> I'm not sure how this could work with migrations. In a sense, it would
>> involve making the auto-generated primary key "swappable", including
>> foreign keys that point to it. This sounds like a headache.
>>
>> I haven't thought of a possible solution since Kenneth floated this idea
>> in #django-dev yesterday.
>>
>> On Friday, June 9, 2017 at 7:11:05 PM UTC-4, Curtis Maloney wrote:
>>>
>>> I know people hate settings, but what about one for auto id field type?
>>>
>>> It would let you handle backwards compatibility, uuid, and bigint...
>>>
>>> --
>>> C
>>>
>>>
>>> On 10 June 2017 5:42:42 AM AEST, Jacob Kaplan-Moss <ja...@jacobian.org>
>>> wrote:
>>>>
>>>> I think this would be a good improvement, and I'd like to see it. I've
>>>> been bitten by integers overflowing at least twice I can remember in my
>>>> career, which is two times too many.
>>>>
>>>> However, a major thing we'd have to work out is the upgrade path
>>>> Consider a simple model:
>>>>
>>>> class Person(Model):
>>>> name = CharField()
>>>>
>>>> In Django 1.11, this actually generates a model with an integer `id`
>>>> field. But in we change it, in Django vNext, that `id` field would "turn
>>>> into" a bigint magically without the underlying table changes. That'd be
>>>> confusing: you'd expect the model to be "fixed" by pugrading to vNext, but
>>>> it wouldn't be. I think the migrations engine would detect this as a
>>>> migration (?), so perhaps that's the path forward, but it could still be
>>>> super-confusing. We've never shipped a release of Django that required a
>>>> migration to _all_ your models.
>>>>
>>>> Have you thought about what the upgrade path should look like, Kenneth?
>>>>
>>>> Jacob
>>>>
>>>> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <ken...@heroku.com>
>>>> wrote:
>>>>
>>>>> Dear Django Dev,
>>>>>
>>>>>
>>>>>
>>>>> At Heroku, we have the privilege of seeing an extremely broad range of
>>>>> customers utilizing tools like Django to build their applications and
>>>>> companies. One of the things that we’ve seen customers hit, time and time
>>>>> again when using tools like Django, is integer overflows for primary keys.
>>>>> Their application starts behaving unpredictably once they reach the
>>>>> overflow, not even knowing such a constraint exists, and they often think
>>>>> the problem is with their database provider, rather than with their 
>>>>> schema.
>>>>> Once they realize what is wrong, it’s a relatively trivial fix, but a
>>>>> migration can take several hours to complete, which results in 
>>>>> unacceptable
>>>>> amounts of downtime.
>>>>>
>>>>>
>>>>

Re: Default to BigAutoField

2017-06-09 Thread Collin Anderson
I might be wrong, but if the default changes, won't the migrations detect
it and migrate it just fine, including foreign keys?

All of my migrations have this:
('id', models.AutoField(auto_created=True, primary_key=True,
serialize=False, verbose_name='ID')),

So everyone would either need to manually specify the AutoField to keep the
old behavior, or run makemigrations to auto-generate migrations to
BigAutoField. This seems similar to increasing the max_length of
EmailField, user.username, and user.last_name, though would affect a lot
more models in this case.

(I'm not sure what I think about the setting idea.)

(While we're at it, maybe we could make it a (new) PositiveBigAutoField to
help out the mysql folks and close the oldest open ticket:
https://code.djangoproject.com/ticket/56 :)



On Fri, Jun 9, 2017 at 9:37 PM, Tim Graham <timogra...@gmail.com> wrote:

> I'm not sure how this could work with migrations. In a sense, it would
> involve making the auto-generated primary key "swappable", including
> foreign keys that point to it. This sounds like a headache.
>
> I haven't thought of a possible solution since Kenneth floated this idea
> in #django-dev yesterday.
>
> On Friday, June 9, 2017 at 7:11:05 PM UTC-4, Curtis Maloney wrote:
>>
>> I know people hate settings, but what about one for auto id field type?
>>
>> It would let you handle backwards compatibility, uuid, and bigint...
>>
>> --
>> C
>>
>>
>> On 10 June 2017 5:42:42 AM AEST, Jacob Kaplan-Moss <ja...@jacobian.org>
>> wrote:
>>>
>>> I think this would be a good improvement, and I'd like to see it. I've
>>> been bitten by integers overflowing at least twice I can remember in my
>>> career, which is two times too many.
>>>
>>> However, a major thing we'd have to work out is the upgrade path
>>> Consider a simple model:
>>>
>>> class Person(Model):
>>> name = CharField()
>>>
>>> In Django 1.11, this actually generates a model with an integer `id`
>>> field. But in we change it, in Django vNext, that `id` field would "turn
>>> into" a bigint magically without the underlying table changes. That'd be
>>> confusing: you'd expect the model to be "fixed" by pugrading to vNext, but
>>> it wouldn't be. I think the migrations engine would detect this as a
>>> migration (?), so perhaps that's the path forward, but it could still be
>>> super-confusing. We've never shipped a release of Django that required a
>>> migration to _all_ your models.
>>>
>>> Have you thought about what the upgrade path should look like, Kenneth?
>>>
>>> Jacob
>>>
>>> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <ken...@heroku.com>
>>> wrote:
>>>
>>>> Dear Django Dev,
>>>>
>>>>
>>>>
>>>> At Heroku, we have the privilege of seeing an extremely broad range of
>>>> customers utilizing tools like Django to build their applications and
>>>> companies. One of the things that we’ve seen customers hit, time and time
>>>> again when using tools like Django, is integer overflows for primary keys.
>>>> Their application starts behaving unpredictably once they reach the
>>>> overflow, not even knowing such a constraint exists, and they often think
>>>> the problem is with their database provider, rather than with their schema.
>>>> Once they realize what is wrong, it’s a relatively trivial fix, but a
>>>> migration can take several hours to complete, which results in unacceptable
>>>> amounts of downtime.
>>>>
>>>>
>>>>
>>>> Because of this, Heroku, as a company, would like to encourage bigints
>>>> as a sane reasonable default for primary keys for application models. If
>>>> the Django project agrees with this idea, that would mean that Django would
>>>> provide BigAutoField as the default for ‘id’ instead of AutoField.
>>>>
>>>>
>>>>
>>>> Rails made this change recently
>>>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen
>>>> success in doing so.
>>>>
>>>>
>>>>
>>>> I’m happy to provide the code to do this, but I wanted to discuss it
>>>> here before doing so, to hear what the general consensus was to the
>>>> proposal of such a change.
>>>>
>>>>
>>>>
>>>>
>>>>
>>>> Pros:
>>>>
>>>>-
&

Re: Default to BigAutoField

2017-06-09 Thread Curtis Maloney
I don't see it helping once you hit the problem, but like custom user its a 
recommendable setting for pre planning

--
C


On 10 June 2017 11:37:04 AM AEST, Tim Graham <timogra...@gmail.com> wrote:
>I'm not sure how this could work with migrations. In a sense, it would 
>involve making the auto-generated primary key "swappable", including 
>foreign keys that point to it. This sounds like a headache.
>
>I haven't thought of a possible solution since Kenneth floated this
>idea in 
>#django-dev yesterday.
>
>On Friday, June 9, 2017 at 7:11:05 PM UTC-4, Curtis Maloney wrote:
>>
>> I know people hate settings, but what about one for auto id field
>type?
>>
>> It would let you handle backwards compatibility, uuid, and bigint...
>>
>> --
>> C
>>
>>
>> On 10 June 2017 5:42:42 AM AEST, Jacob Kaplan-Moss
><ja...@jacobian.org 
>> > wrote:
>>>
>>> I think this would be a good improvement, and I'd like to see it.
>I've 
>>> been bitten by integers overflowing at least twice I can remember in
>my 
>>> career, which is two times too many.
>>>
>>> However, a major thing we'd have to work out is the upgrade path
>Consider 
>>> a simple model:
>>>
>>> class Person(Model):
>>> name = CharField()
>>>
>>> In Django 1.11, this actually generates a model with an integer `id`
>
>>> field. But in we change it, in Django vNext, that `id` field would
>"turn 
>>> into" a bigint magically without the underlying table changes.
>That'd be 
>>> confusing: you'd expect the model to be "fixed" by pugrading to
>vNext, but 
>>> it wouldn't be. I think the migrations engine would detect this as a
>
>>> migration (?), so perhaps that's the path forward, but it could
>still be 
>>> super-confusing. We've never shipped a release of Django that
>required a 
>>> migration to _all_ your models.
>>>
>>> Have you thought about what the upgrade path should look like,
>Kenneth?
>>>
>>> Jacob
>>>
>>> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <ken...@heroku.com 
>>> > wrote:
>>>
>>>> Dear Django Dev,
>>>>
>>>>  
>>>>
>>>> At Heroku, we have the privilege of seeing an extremely broad range
>of 
>>>> customers utilizing tools like Django to build their applications
>and 
>>>> companies. One of the things that we’ve seen customers hit, time
>and time 
>>>> again when using tools like Django, is integer overflows for
>primary keys. 
>>>> Their application starts behaving unpredictably once they reach the
>
>>>> overflow, not even knowing such a constraint exists, and they often
>think 
>>>> the problem is with their database provider, rather than with their
>schema. 
>>>> Once they realize what is wrong, it’s a relatively trivial fix, but
>a 
>>>> migration can take several hours to complete, which results in
>unacceptable 
>>>> amounts of downtime.
>>>>
>>>>  
>>>>
>>>> Because of this, Heroku, as a company, would like to encourage
>bigints 
>>>> as a sane reasonable default for primary keys for application
>models. If 
>>>> the Django project agrees with this idea, that would mean that
>Django would 
>>>> provide BigAutoField as the default for ‘id’ instead of AutoField. 
>>>>
>>>>  
>>>>
>>>> Rails made this change recently 
>>>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen 
>>>> success in doing so. 
>>>>
>>>>  
>>>>
>>>> I’m happy to provide the code to do this, but I wanted to discuss
>it 
>>>> here before doing so, to hear what the general consensus was to the
>
>>>> proposal of such a change. 
>>>>
>>>>  
>>>>
>>>>  
>>>>
>>>> Pros:
>>>>
>>>>- 
>>>>
>>>>Users of Django, following the docs, won’t accidentally hit the
>int 
>>>>overflow barrier. 
>>>>- 
>>>>
>>>>Encourages best-practices from the beginning. 
>>>>- 
>>>>
>>>>Bigints don’t take up much more storage than ints when using 
>>>>Postgres. 
>>>>- 
>>>>
>>>>In-line with other frameworks movi

Re: Default to BigAutoField

2017-06-09 Thread Tim Graham
I'm not sure how this could work with migrations. In a sense, it would 
involve making the auto-generated primary key "swappable", including 
foreign keys that point to it. This sounds like a headache.

I haven't thought of a possible solution since Kenneth floated this idea in 
#django-dev yesterday.

On Friday, June 9, 2017 at 7:11:05 PM UTC-4, Curtis Maloney wrote:
>
> I know people hate settings, but what about one for auto id field type?
>
> It would let you handle backwards compatibility, uuid, and bigint...
>
> --
> C
>
>
> On 10 June 2017 5:42:42 AM AEST, Jacob Kaplan-Moss <ja...@jacobian.org 
> > wrote:
>>
>> I think this would be a good improvement, and I'd like to see it. I've 
>> been bitten by integers overflowing at least twice I can remember in my 
>> career, which is two times too many.
>>
>> However, a major thing we'd have to work out is the upgrade path Consider 
>> a simple model:
>>
>> class Person(Model):
>> name = CharField()
>>
>> In Django 1.11, this actually generates a model with an integer `id` 
>> field. But in we change it, in Django vNext, that `id` field would "turn 
>> into" a bigint magically without the underlying table changes. That'd be 
>> confusing: you'd expect the model to be "fixed" by pugrading to vNext, but 
>> it wouldn't be. I think the migrations engine would detect this as a 
>> migration (?), so perhaps that's the path forward, but it could still be 
>> super-confusing. We've never shipped a release of Django that required a 
>> migration to _all_ your models.
>>
>> Have you thought about what the upgrade path should look like, Kenneth?
>>
>> Jacob
>>
>> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <ken...@heroku.com 
>> > wrote:
>>
>>> Dear Django Dev,
>>>
>>>  
>>>
>>> At Heroku, we have the privilege of seeing an extremely broad range of 
>>> customers utilizing tools like Django to build their applications and 
>>> companies. One of the things that we’ve seen customers hit, time and time 
>>> again when using tools like Django, is integer overflows for primary keys. 
>>> Their application starts behaving unpredictably once they reach the 
>>> overflow, not even knowing such a constraint exists, and they often think 
>>> the problem is with their database provider, rather than with their schema. 
>>> Once they realize what is wrong, it’s a relatively trivial fix, but a 
>>> migration can take several hours to complete, which results in unacceptable 
>>> amounts of downtime.
>>>
>>>  
>>>
>>> Because of this, Heroku, as a company, would like to encourage bigints 
>>> as a sane reasonable default for primary keys for application models. If 
>>> the Django project agrees with this idea, that would mean that Django would 
>>> provide BigAutoField as the default for ‘id’ instead of AutoField. 
>>>
>>>  
>>>
>>> Rails made this change recently 
>>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen 
>>> success in doing so. 
>>>
>>>  
>>>
>>> I’m happy to provide the code to do this, but I wanted to discuss it 
>>> here before doing so, to hear what the general consensus was to the 
>>> proposal of such a change. 
>>>
>>>  
>>>
>>>  
>>>
>>> Pros:
>>>
>>>- 
>>>
>>>Users of Django, following the docs, won’t accidentally hit the int 
>>>overflow barrier. 
>>>- 
>>>
>>>Encourages best-practices from the beginning. 
>>>- 
>>>
>>>Bigints don’t take up much more storage than ints when using 
>>>Postgres. 
>>>- 
>>>
>>>In-line with other frameworks moving forward on this issue, like 
>>>Rails <http://www.mccartie.com/2016/12/05/rails-5.1.html>.
>>>
>>>  
>>>
>>> Cons:
>>>
>>>- 
>>>
>>>Backwards compatibility would need to be considered. 
>>>
>>>  
>>> Why not UUID?
>>>
>>>  
>>>
>>> I agree! I love using UUID for my primary keys, and I think a patch to 
>>> Django which provides an AutoUUIDField would be wonderful. However, there 
>>> are a few major drawbacks to making this the new default:
>>>
>>>  
>>>
>>>1. 
>>>  

Re: Default to BigAutoField

2017-06-09 Thread Curtis Maloney
I know people hate settings, but what about one for auto id field type?

It would let you handle backwards compatibility, uuid, and bigint...

--
C


On 10 June 2017 5:42:42 AM AEST, Jacob Kaplan-Moss <ja...@jacobian.org> wrote:
>I think this would be a good improvement, and I'd like to see it. I've
>been
>bitten by integers overflowing at least twice I can remember in my
>career,
>which is two times too many.
>
>However, a major thing we'd have to work out is the upgrade path
>Consider a
>simple model:
>
>class Person(Model):
>name = CharField()
>
>In Django 1.11, this actually generates a model with an integer `id`
>field.
>But in we change it, in Django vNext, that `id` field would "turn into"
>a
>bigint magically without the underlying table changes. That'd be
>confusing:
>you'd expect the model to be "fixed" by pugrading to vNext, but it
>wouldn't
>be. I think the migrations engine would detect this as a migration (?),
>so
>perhaps that's the path forward, but it could still be super-confusing.
>We've never shipped a release of Django that required a migration to
>_all_
>your models.
>
>Have you thought about what the upgrade path should look like, Kenneth?
>
>Jacob
>
>On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <kenn...@heroku.com>
>wrote:
>
>> Dear Django Dev,
>>
>>
>>
>> At Heroku, we have the privilege of seeing an extremely broad range
>of
>> customers utilizing tools like Django to build their applications and
>> companies. One of the things that we’ve seen customers hit, time and
>time
>> again when using tools like Django, is integer overflows for primary
>keys.
>> Their application starts behaving unpredictably once they reach the
>> overflow, not even knowing such a constraint exists, and they often
>think
>> the problem is with their database provider, rather than with their
>schema.
>> Once they realize what is wrong, it’s a relatively trivial fix, but a
>> migration can take several hours to complete, which results in
>unacceptable
>> amounts of downtime.
>>
>>
>>
>> Because of this, Heroku, as a company, would like to encourage
>bigints as
>> a sane reasonable default for primary keys for application models. If
>the
>> Django project agrees with this idea, that would mean that Django
>would
>> provide BigAutoField as the default for ‘id’ instead of AutoField.
>>
>>
>>
>> Rails made this change recently
>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen
>success
>> in doing so.
>>
>>
>>
>> I’m happy to provide the code to do this, but I wanted to discuss it
>here
>> before doing so, to hear what the general consensus was to the
>proposal of
>> such a change.
>>
>>
>>
>>
>>
>> Pros:
>>
>>-
>>
>>Users of Django, following the docs, won’t accidentally hit the
>int
>>overflow barrier.
>>-
>>
>>Encourages best-practices from the beginning.
>>-
>>
>>Bigints don’t take up much more storage than ints when using
>Postgres.
>>-
>>
>>In-line with other frameworks moving forward on this issue, like
>Rails
>><http://www.mccartie.com/2016/12/05/rails-5.1.html>.
>>
>>
>>
>> Cons:
>>
>>-
>>
>>Backwards compatibility would need to be considered.
>>
>>
>> Why not UUID?
>>
>>
>>
>> I agree! I love using UUID for my primary keys, and I think a patch
>to
>> Django which provides an AutoUUIDField would be wonderful. However,
>there
>> are a few major drawbacks to making this the new default:
>>
>>
>>
>>1.
>>
>>It’s confusing to new users, would make onboarding process more
>>difficult.
>>2.
>>
>>UUID is difficult to implement in MySQL.
>>3.
>>
>>UUID has larger storage requirements.
>>4.
>>
>>Incrementing IDs are actually useful.
>>
>>
>>
>>
>> So, my proposal is to simply lift the int barrier to a bigint barrier
>for
>> new Django applications, and I think it will save a lot of developers
>a lot
>> of pain in the long run.
>>
>>
>>
>> Many thanks,
>>
>>
>>
>> Kenneth Reitz
>>
>> Heroku Python
>>
>> --
>> You received this message because you are subscribed to the Google
>Groups
>> "Django developers (Contributions to Django itself)" group.

Re: Default to BigAutoField

2017-06-09 Thread Kenneth Reitz
However, it should also be noted that those same larger applications are the 
ones that are likely to run into this problem eventually, so perhaps forcing 
the migration is the best path moving forward. 

Interested in hearing thoughts about this.

--
Kenneth Reitz

> On Jun 9, 2017, at 3:54 PM, Kenneth Reitz <kenn...@heroku.com> wrote:
> 
> My initial thought was to just have this apply to *new* Django applications, 
> if that's possible.
> 
> Running this migration could take quite some time on some larger apps, and 
> would require a non-trivial amount of time to execute. 
> 
> --
> Kenneth Reitz
> 
>> On Jun 9, 2017, at 3:53 PM, Tom Forbes <t...@tomforb.es 
>> <mailto:t...@tomforb.es>> wrote:
>> 
>> How would this work with generic foreign keys as well? Those migrations 
>> couldn't be automatic.
>> 
>> On 9 Jun 2017 20:43, "Jacob Kaplan-Moss" <ja...@jacobian.org 
>> <mailto:ja...@jacobian.org>> wrote:
>> I think this would be a good improvement, and I'd like to see it. I've been 
>> bitten by integers overflowing at least twice I can remember in my career, 
>> which is two times too many.
>> 
>> However, a major thing we'd have to work out is the upgrade path Consider a 
>> simple model:
>> 
>> class Person(Model):
>> name = CharField()
>> 
>> In Django 1.11, this actually generates a model with an integer `id` field. 
>> But in we change it, in Django vNext, that `id` field would "turn into" a 
>> bigint magically without the underlying table changes. That'd be confusing: 
>> you'd expect the model to be "fixed" by pugrading to vNext, but it wouldn't 
>> be. I think the migrations engine would detect this as a migration (?), so 
>> perhaps that's the path forward, but it could still be super-confusing. 
>> We've never shipped a release of Django that required a migration to _all_ 
>> your models.
>> 
>> Have you thought about what the upgrade path should look like, Kenneth?
>> 
>> Jacob
>> 
>> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <kenn...@heroku.com 
>> <mailto:kenn...@heroku.com>> wrote:
>> Dear Django Dev,
>>  
>> At Heroku, we have the privilege of seeing an extremely broad range of 
>> customers utilizing tools like Django to build their applications and 
>> companies. One of the things that we’ve seen customers hit, time and time 
>> again when using tools like Django, is integer overflows for primary keys. 
>> Their application starts behaving unpredictably once they reach the 
>> overflow, not even knowing such a constraint exists, and they often think 
>> the problem is with their database provider, rather than with their schema. 
>> Once they realize what is wrong, it’s a relatively trivial fix, but a 
>> migration can take several hours to complete, which results in unacceptable 
>> amounts of downtime.
>>  
>> Because of this, Heroku, as a company, would like to encourage bigints as a 
>> sane reasonable default for primary keys for application models. If the 
>> Django project agrees with this idea, that would mean that Django would 
>> provide BigAutoField as the default for ‘id’ instead of AutoField. 
>>  
>> Rails made this change recently 
>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen success in 
>> doing so. 
>>  
>> I’m happy to provide the code to do this, but I wanted to discuss it here 
>> before doing so, to hear what the general consensus was to the proposal of 
>> such a change. 
>>  
>>  
>> Pros:
>> Users of Django, following the docs, won’t accidentally hit the int overflow 
>> barrier. 
>> Encourages best-practices from the beginning. 
>> Bigints don’t take up much more storage than ints when using Postgres. 
>> In-line with other frameworks moving forward on this issue, like Rails 
>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>.
>>  
>> Cons:
>> Backwards compatibility would need to be considered. 
>>  
>> Why not UUID?
>>  
>> I agree! I love using UUID for my primary keys, and I think a patch to 
>> Django which provides an AutoUUIDField would be wonderful. However, there 
>> are a few major drawbacks to making this the new default:
>>  
>> It’s confusing to new users, would make onboarding process more difficult. 
>> UUID is difficult to implement in MySQL. 
>> UUID has larger storage requirements. 
>> Incrementing IDs are actually useful. 
>>  
>> 
>> So, my proposal is to simply lift the int barrier t

Re: Default to BigAutoField

2017-06-09 Thread Kenneth Reitz
My initial thought was to just have this apply to *new* Django applications, if 
that's possible.

Running this migration could take quite some time on some larger apps, and 
would require a non-trivial amount of time to execute. 

--
Kenneth Reitz

> On Jun 9, 2017, at 3:53 PM, Tom Forbes <t...@tomforb.es> wrote:
> 
> How would this work with generic foreign keys as well? Those migrations 
> couldn't be automatic.
> 
> On 9 Jun 2017 20:43, "Jacob Kaplan-Moss" <ja...@jacobian.org 
> <mailto:ja...@jacobian.org>> wrote:
> I think this would be a good improvement, and I'd like to see it. I've been 
> bitten by integers overflowing at least twice I can remember in my career, 
> which is two times too many.
> 
> However, a major thing we'd have to work out is the upgrade path Consider a 
> simple model:
> 
> class Person(Model):
> name = CharField()
> 
> In Django 1.11, this actually generates a model with an integer `id` field. 
> But in we change it, in Django vNext, that `id` field would "turn into" a 
> bigint magically without the underlying table changes. That'd be confusing: 
> you'd expect the model to be "fixed" by pugrading to vNext, but it wouldn't 
> be. I think the migrations engine would detect this as a migration (?), so 
> perhaps that's the path forward, but it could still be super-confusing. We've 
> never shipped a release of Django that required a migration to _all_ your 
> models.
> 
> Have you thought about what the upgrade path should look like, Kenneth?
> 
> Jacob
> 
> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <kenn...@heroku.com 
> <mailto:kenn...@heroku.com>> wrote:
> Dear Django Dev,
>  
> At Heroku, we have the privilege of seeing an extremely broad range of 
> customers utilizing tools like Django to build their applications and 
> companies. One of the things that we’ve seen customers hit, time and time 
> again when using tools like Django, is integer overflows for primary keys. 
> Their application starts behaving unpredictably once they reach the overflow, 
> not even knowing such a constraint exists, and they often think the problem 
> is with their database provider, rather than with their schema. Once they 
> realize what is wrong, it’s a relatively trivial fix, but a migration can 
> take several hours to complete, which results in unacceptable amounts of 
> downtime.
>  
> Because of this, Heroku, as a company, would like to encourage bigints as a 
> sane reasonable default for primary keys for application models. If the 
> Django project agrees with this idea, that would mean that Django would 
> provide BigAutoField as the default for ‘id’ instead of AutoField. 
>  
> Rails made this change recently 
> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen success in 
> doing so. 
>  
> I’m happy to provide the code to do this, but I wanted to discuss it here 
> before doing so, to hear what the general consensus was to the proposal of 
> such a change. 
>  
>  
> Pros:
> Users of Django, following the docs, won’t accidentally hit the int overflow 
> barrier. 
> Encourages best-practices from the beginning. 
> Bigints don’t take up much more storage than ints when using Postgres. 
> In-line with other frameworks moving forward on this issue, like Rails 
> <http://www.mccartie.com/2016/12/05/rails-5.1.html>.
>  
> Cons:
> Backwards compatibility would need to be considered. 
>  
> Why not UUID?
>  
> I agree! I love using UUID for my primary keys, and I think a patch to Django 
> which provides an AutoUUIDField would be wonderful. However, there are a few 
> major drawbacks to making this the new default:
>  
> It’s confusing to new users, would make onboarding process more difficult. 
> UUID is difficult to implement in MySQL. 
> UUID has larger storage requirements. 
> Incrementing IDs are actually useful. 
>  
> 
> So, my proposal is to simply lift the int barrier to a bigint barrier for new 
> Django applications, and I think it will save a lot of developers a lot of 
> pain in the long run. 
>  
> Many thanks,
>  
> Kenneth Reitz
> Heroku Python
> 
> 
> -- 
> 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 django-developers+unsubscr...@googlegroups.com 
> <mailto:django-developers+unsubscr...@googlegroups.com>.
> To post to this group, send email to django-developers@googlegroups.com 
> <mailto:django-developers@googlegroups.com>.
> Visit this group at https://groups.google

Re: Default to BigAutoField

2017-06-09 Thread Tom Forbes
How would this work with generic foreign keys as well? Those migrations
couldn't be automatic.

On 9 Jun 2017 20:43, "Jacob Kaplan-Moss" <ja...@jacobian.org> wrote:

> I think this would be a good improvement, and I'd like to see it. I've
> been bitten by integers overflowing at least twice I can remember in my
> career, which is two times too many.
>
> However, a major thing we'd have to work out is the upgrade path Consider
> a simple model:
>
> class Person(Model):
> name = CharField()
>
> In Django 1.11, this actually generates a model with an integer `id`
> field. But in we change it, in Django vNext, that `id` field would "turn
> into" a bigint magically without the underlying table changes. That'd be
> confusing: you'd expect the model to be "fixed" by pugrading to vNext, but
> it wouldn't be. I think the migrations engine would detect this as a
> migration (?), so perhaps that's the path forward, but it could still be
> super-confusing. We've never shipped a release of Django that required a
> migration to _all_ your models.
>
> Have you thought about what the upgrade path should look like, Kenneth?
>
> Jacob
>
> On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <kenn...@heroku.com> wrote:
>
>> Dear Django Dev,
>>
>>
>>
>> At Heroku, we have the privilege of seeing an extremely broad range of
>> customers utilizing tools like Django to build their applications and
>> companies. One of the things that we’ve seen customers hit, time and time
>> again when using tools like Django, is integer overflows for primary keys.
>> Their application starts behaving unpredictably once they reach the
>> overflow, not even knowing such a constraint exists, and they often think
>> the problem is with their database provider, rather than with their schema.
>> Once they realize what is wrong, it’s a relatively trivial fix, but a
>> migration can take several hours to complete, which results in unacceptable
>> amounts of downtime.
>>
>>
>>
>> Because of this, Heroku, as a company, would like to encourage bigints as
>> a sane reasonable default for primary keys for application models. If the
>> Django project agrees with this idea, that would mean that Django would
>> provide BigAutoField as the default for ‘id’ instead of AutoField.
>>
>>
>>
>> Rails made this change recently
>> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen
>> success in doing so.
>>
>>
>>
>> I’m happy to provide the code to do this, but I wanted to discuss it here
>> before doing so, to hear what the general consensus was to the proposal of
>> such a change.
>>
>>
>>
>>
>>
>> Pros:
>>
>>-
>>
>>Users of Django, following the docs, won’t accidentally hit the int
>>overflow barrier.
>>-
>>
>>Encourages best-practices from the beginning.
>>-
>>
>>Bigints don’t take up much more storage than ints when using
>>Postgres.
>>-
>>
>>In-line with other frameworks moving forward on this issue, like Rails
>><http://www.mccartie.com/2016/12/05/rails-5.1.html>.
>>
>>
>>
>> Cons:
>>
>>-
>>
>>Backwards compatibility would need to be considered.
>>
>>
>> Why not UUID?
>>
>>
>>
>> I agree! I love using UUID for my primary keys, and I think a patch to
>> Django which provides an AutoUUIDField would be wonderful. However, there
>> are a few major drawbacks to making this the new default:
>>
>>
>>
>>1.
>>
>>It’s confusing to new users, would make onboarding process more
>>difficult.
>>2.
>>
>>UUID is difficult to implement in MySQL.
>>3.
>>
>>UUID has larger storage requirements.
>>4.
>>
>>Incrementing IDs are actually useful.
>>
>>
>>
>>
>> So, my proposal is to simply lift the int barrier to a bigint barrier for
>> new Django applications, and I think it will save a lot of developers a lot
>> of pain in the long run.
>>
>>
>>
>> Many thanks,
>>
>>
>>
>> Kenneth Reitz
>>
>> Heroku Python
>>
>> --
>> 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 django-developers+unsubscr

Re: Default to BigAutoField

2017-06-09 Thread Jacob Kaplan-Moss
I think this would be a good improvement, and I'd like to see it. I've been
bitten by integers overflowing at least twice I can remember in my career,
which is two times too many.

However, a major thing we'd have to work out is the upgrade path Consider a
simple model:

class Person(Model):
name = CharField()

In Django 1.11, this actually generates a model with an integer `id` field.
But in we change it, in Django vNext, that `id` field would "turn into" a
bigint magically without the underlying table changes. That'd be confusing:
you'd expect the model to be "fixed" by pugrading to vNext, but it wouldn't
be. I think the migrations engine would detect this as a migration (?), so
perhaps that's the path forward, but it could still be super-confusing.
We've never shipped a release of Django that required a migration to _all_
your models.

Have you thought about what the upgrade path should look like, Kenneth?

Jacob

On Fri, Jun 9, 2017 at 11:24 AM, Kenneth Reitz <kenn...@heroku.com> wrote:

> Dear Django Dev,
>
>
>
> At Heroku, we have the privilege of seeing an extremely broad range of
> customers utilizing tools like Django to build their applications and
> companies. One of the things that we’ve seen customers hit, time and time
> again when using tools like Django, is integer overflows for primary keys.
> Their application starts behaving unpredictably once they reach the
> overflow, not even knowing such a constraint exists, and they often think
> the problem is with their database provider, rather than with their schema.
> Once they realize what is wrong, it’s a relatively trivial fix, but a
> migration can take several hours to complete, which results in unacceptable
> amounts of downtime.
>
>
>
> Because of this, Heroku, as a company, would like to encourage bigints as
> a sane reasonable default for primary keys for application models. If the
> Django project agrees with this idea, that would mean that Django would
> provide BigAutoField as the default for ‘id’ instead of AutoField.
>
>
>
> Rails made this change recently
> <http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen success
> in doing so.
>
>
>
> I’m happy to provide the code to do this, but I wanted to discuss it here
> before doing so, to hear what the general consensus was to the proposal of
> such a change.
>
>
>
>
>
> Pros:
>
>-
>
>Users of Django, following the docs, won’t accidentally hit the int
>overflow barrier.
>-
>
>Encourages best-practices from the beginning.
>-
>
>Bigints don’t take up much more storage than ints when using Postgres.
>-
>
>In-line with other frameworks moving forward on this issue, like Rails
><http://www.mccartie.com/2016/12/05/rails-5.1.html>.
>
>
>
> Cons:
>
>-
>
>Backwards compatibility would need to be considered.
>
>
> Why not UUID?
>
>
>
> I agree! I love using UUID for my primary keys, and I think a patch to
> Django which provides an AutoUUIDField would be wonderful. However, there
> are a few major drawbacks to making this the new default:
>
>
>
>1.
>
>It’s confusing to new users, would make onboarding process more
>difficult.
>2.
>
>UUID is difficult to implement in MySQL.
>3.
>
>UUID has larger storage requirements.
>4.
>
>Incrementing IDs are actually useful.
>
>
>
>
> So, my proposal is to simply lift the int barrier to a bigint barrier for
> new Django applications, and I think it will save a lot of developers a lot
> of pain in the long run.
>
>
>
> Many thanks,
>
>
>
> Kenneth Reitz
>
> Heroku Python
>
> --
> 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 django-developers+unsubscr...@googlegroups.com.
> To post to this group, send email to django-developers@googlegroups.com.
> 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/6fe3401c-4404-4bd8-9d22-
> 58df95cd1348%40googlegroups.com
> <https://groups.google.com/d/msgid/django-developers/6fe3401c-4404-4bd8-9d22-58df95cd1348%40googlegroups.com?utm_medium=email_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 receivin

Default to BigAutoField

2017-06-09 Thread Kenneth Reitz


Dear Django Dev,

 

At Heroku, we have the privilege of seeing an extremely broad range of 
customers utilizing tools like Django to build their applications and 
companies. One of the things that we’ve seen customers hit, time and time 
again when using tools like Django, is integer overflows for primary keys. 
Their application starts behaving unpredictably once they reach the 
overflow, not even knowing such a constraint exists, and they often think 
the problem is with their database provider, rather than with their schema. 
Once they realize what is wrong, it’s a relatively trivial fix, but a 
migration can take several hours to complete, which results in unacceptable 
amounts of downtime.

 

Because of this, Heroku, as a company, would like to encourage bigints as a 
sane reasonable default for primary keys for application models. If the 
Django project agrees with this idea, that would mean that Django would 
provide BigAutoField as the default for ‘id’ instead of AutoField. 

 

Rails made this change recently 
<http://www.mccartie.com/2016/12/05/rails-5.1.html>, and has seen success 
in doing so. 

 

I’m happy to provide the code to do this, but I wanted to discuss it here 
before doing so, to hear what the general consensus was to the proposal of 
such a change. 

 

 

Pros:

   - 
   
   Users of Django, following the docs, won’t accidentally hit the int 
   overflow barrier. 
   - 
   
   Encourages best-practices from the beginning. 
   - 
   
   Bigints don’t take up much more storage than ints when using Postgres. 
   - 
   
   In-line with other frameworks moving forward on this issue, like Rails 
   <http://www.mccartie.com/2016/12/05/rails-5.1.html>.
   
 

Cons:

   - 
   
   Backwards compatibility would need to be considered. 
   
 
Why not UUID?

 

I agree! I love using UUID for my primary keys, and I think a patch to 
Django which provides an AutoUUIDField would be wonderful. However, there 
are a few major drawbacks to making this the new default:

 

   1. 
   
   It’s confusing to new users, would make onboarding process more 
   difficult. 
   2. 
   
   UUID is difficult to implement in MySQL. 
   3. 
   
   UUID has larger storage requirements. 
   4. 
   
   Incrementing IDs are actually useful. 
   
 


So, my proposal is to simply lift the int barrier to a bigint barrier for 
new Django applications, and I think it will save a lot of developers a lot 
of pain in the long run. 

 

Many thanks,

 

Kenneth Reitz

Heroku Python

-- 
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 django-developers+unsubscr...@googlegroups.com.
To post to this group, send email to django-developers@googlegroups.com.
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/6fe3401c-4404-4bd8-9d22-58df95cd1348%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: BigAutoField

2013-01-23 Thread Anssi Kääriäinen
On 23 tammi, 16:09, SteveB <smbroo...@gmail.com> wrote:
> Hi,
> Can anybody provide an update on the request to define a BigAutoField in
> Django?
> We could really use this model field type without having to do workarounds
> and customizations.
> Can any of the Django developers comment on when this will be released?

There isn't any release schedule for features like this.

I have been playing around an idea of having an AutoGeneratedField().
The basic idea is that such a field has to components, internal_field,
and generator.

The internal field is a field that stores the data. The generator is
an object that generates values for that field on save.

The generator API would be something like this:
pre_save(self, field, obj, connection, created)
returning(self, field, obj, connection, created)
post_save(self, field, obj, connection, created, returned_vals)

Consider AutoField as an example. Here the internal_field is an
IntegerField, and the generator is a SerialGenerator.

For autofield the definition would be something like this (just MySQL
and PostgreSQL support to make this example shorter):

pre_save():
return NotImplemented

returning(self, field, obj, connection, created):
if created and connection.vendor == 'postgres':
 return field.column
return NotImplemented

post_save(self, field, obj, connection, created, returned_vals):
if created and connection.vendor == 'mysql':
  setattr(obj, field.attname, connection.insert_id())
elif field in returned_vals:
  setattr(obj, field.attname, returned_vals[field])

In reality the SerialGenerator implementations should be done in
connection.ops for 3rd party backend support. For this example that
would just complicate things.

Why this way? Well, a UUIDGenerator would be:
def pre_save(self, field, obj, connection, created):
 if created:
 setattr(obj, field.attname, generate_uuid())
(or, you could use returning() if you want to generate the value in
the DB).

BigAutoField? AutoGeneratedField(internal_field=BigIntegerField,
generator=SerialGenerator).

I am pretty sure we could make this work. This would also allow doing
DateTimeField with default of database generated now() for created/
modified times. Or, maybe there is some trigger modifying some field's
value on save, and you want to return that back to Python on save.

There are a lot of details. The API likely doesn't work as-is
(database creation SQL at least needs some support).

I don't think I will have time to work on this anytime soon. This is
likely going to take a lot of time to do properly.

(Yeah, I know, implementing all this is a bit overkill if all you want
is BigAutoField).

 - Anssi

-- 
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 
django-developers+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




Re: BigAutoField

2013-01-23 Thread Wim Feijen
Hi Steve,

Django is an open source product made and improved by many volunteers.

Probably you are reffering to: 
https://code.djangoproject.com/ticket/14286

What needs to get done to get the patch accepted in Django, is that 
somebody (really anybody - could be you) looks at the latest patch 
provided. maybe makes some improvements for suggestions and if all is well, 
it can be marked: Ready for checkin.

After that, it is a core developers "job" (again, it is voluntary) to 
either implement, or give constructive feedback on why not. Some tickets 
are easy and some are hard.

The best way to get a core developers attention is to do a 5 for 1, which 
means if you check 5 patches of other people, a core developer is willing 
to look at your patch / the patch you would like to have in Django.

More information on contributing to Django is here:
https://docs.djangoproject.com/en/dev/internals/contributing/

Good luck!

Wim

On Wednesday, 23 January 2013 15:09:29 UTC+1, SteveB wrote:
>
> Hi,
> Can anybody provide an update on the request to define a BigAutoField in 
> Django?
> We could really use this model field type without having to do workarounds 
> and customizations.
> Can any of the Django developers comment on when this will be released?
>
> Thanks,
> Steve

-- 
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 
django-developers+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.




BigAutoField

2013-01-23 Thread SteveB
Hi,
Can anybody provide an update on the request to define a BigAutoField in 
Django?
We could really use this model field type without having to do workarounds 
and customizations.
Can any of the Django developers comment on when this will be released?

Thanks,
Steve

-- 
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 
django-developers+unsubscr...@googlegroups.com.
Visit this group at http://groups.google.com/group/django-developers?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.