Re: [Django] #30431: Migration hangs when using UUIDField with unique default value & multiple databases

2019-05-02 Thread Django
#30431: Migration hangs when using UUIDField with unique default value & 
multiple
databases
-+-
 Reporter:  mandm|Owner:  nobody
 Type:  Bug  |   Status:  new
Component:  Migrations   |  Version:  1.11
 Severity:  Normal   |   Resolution:
 Keywords:  migrations, uuid,| Triage Stage:
  uuidfield, database router,|  Unreviewed
  multiple database  |
Has patch:  0|  Needs documentation:  0
  Needs tests:  0|  Patch needs improvement:  0
Easy pickings:  0|UI/UX:  0
-+-
Description changed by mandm:

Old description:

> I'm trying to add a UUIDField in an existing user model following this
> method (with unique=True & default=uuid.uuid4).
> https://docs.djangoproject.com/en/1.11/howto/writing-migrations
> /#migrations-that-add-unique-fields
>
> This works with a single database but hangs in the following scenarios
> with multiple databases :
>
> - Migration without `--database=foobar` works
> - Migration with `--database=foobar` option hangs
> - Migration without `--database=foobar`, but with `using('foobar')` in
> the query in gen_uuid function hangs
>

>
> Here's a snippet of the code I've used. I would be glad to provide
> additional information to reproduce the issue.
>
> User model :
>
> {{{
> class CustomUser(AbstractUser):
> address = models.TextField()
> uniq_id = models.UUIDField(unique=True, default=uuid.uuid4)
>
> class Meta:
> db_table = 'customuser'
> }}}
>

> Migration file
>

> {{{
> def gen_uuid(apps, schema_editor):
> UserModel = apps.get_model('myapp', 'customuser')
> for row in UserModel.objects.all(): #
> .objects.using('foobar').all(): -- HANGS !
> row.uniq_id = uuid.uuid4()
> row.save(update_fields=['uniq_id']) # .save(using='foobar', ...)
> -- HANGS with database routers !
>
> class Migration(migrations.Migration):
> dependencies = [
> ('myapp', '003_previous_migration'),
> ]
>
> operations = [
> migrations.AddField(
> model_name='customuser',
> name='uniq_id',
> field=models.UUIDField(default=uuid.uuid4, null=True),
> ),
> migrations.RunPython(gen_uuid,
> reverse_code=migrations.RunPython.noop),
> migrations.AlterField(
> model_name='customuser',
> name='uniq_id',
> field=models.UUIDField(default=uuid.uuid4, unique=True),
> ),
> ]
> }}}

New description:

 I'm trying to add a UUIDField in an existing user model following this
 method (with unique=True & default=uuid.uuid4).
 https://docs.djangoproject.com/en/1.11/howto/writing-migrations
 /#migrations-that-add-unique-fields

 This works with a single database but hangs in the following scenarios
 with multiple databases :

 - Hangs ! Migration with option `--database=foobar`
 - Hangs ! Migration without option `--database=foobar`, but with
 `using('foobar')` in the query in gen_uuid function
 - Works ! Migration without option `--database=foobar`


 Here's a snippet of the code I've used. I would be glad to provide
 additional information to reproduce the issue.

 User model :

 {{{
 class CustomUser(AbstractUser):
 address = models.TextField()
 uniq_id = models.UUIDField(unique=True, default=uuid.uuid4)

 class Meta:
 db_table = 'customuser'
 }}}


 Migration file


 {{{
 def gen_uuid(apps, schema_editor):
 UserModel = apps.get_model('myapp', 'customuser')
 for row in UserModel.objects.all(): #
 .objects.using('foobar').all(): -- HANGS !
 row.uniq_id = uuid.uuid4()
 row.save(update_fields=['uniq_id']) # .save(using='foobar', ...)
 -- HANGS with database routers !

 class Migration(migrations.Migration):
 dependencies = [
 ('myapp', '003_previous_migration'),
 ]

 operations = [
 migrations.AddField(
 model_name='customuser',
 name='uniq_id',
 field=models.UUIDField(default=uuid.uuid4, null=True),
 ),
 migrations.RunPython(gen_uuid,
 reverse_code=migrations.RunPython.noop),
 migrations.AlterField(
 model_name='customuser',
 name='uniq_id',
 field=models.UUIDField(default=uuid.uuid4, unique=True),
 ),
 ]
 }}}

--

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 

[Django] #30431: Migration hangs when using UUIDField with unique default value & multiple databases

2019-05-02 Thread Django
#30431: Migration hangs when using UUIDField with unique default value & 
multiple
databases
-+-
   Reporter:  mandm  |  Owner:  nobody
   Type:  Bug| Status:  new
  Component: |Version:  1.11
  Migrations |   Keywords:  migrations, uuid,
   Severity:  Normal |  uuidfield, database router,
   Triage Stage: |  multiple database
  Unreviewed |  Has patch:  0
Needs documentation:  0  |Needs tests:  0
Patch needs improvement:  0  |  Easy pickings:  0
  UI/UX:  0  |
-+-
 I'm trying to add a UUIDField in an existing user model following this
 method (with unique=True & default=uuid.uuid4).
 https://docs.djangoproject.com/en/1.11/howto/writing-migrations
 /#migrations-that-add-unique-fields

 This works with a single database but hangs in the following scenarios
 with multiple databases :

 - Migration without `--database=foobar` works
 - Migration with `--database=foobar` option hangs
 - Migration without `--database=foobar`, but with `using('foobar')` in the
 query in gen_uuid function hangs



 Here's a snippet of the code I've used. I would be glad to provide
 additional information to reproduce the issue.

 User model :

 {{{
 class CustomUser(AbstractUser):
 address = models.TextField()
 uniq_id = models.UUIDField(unique=True, default=uuid.uuid4)

 class Meta:
 db_table = 'customuser'
 }}}


 Migration file


 {{{
 def gen_uuid(apps, schema_editor):
 UserModel = apps.get_model('myapp', 'customuser')
 for row in UserModel.objects.all(): #
 .objects.using('foobar').all(): -- HANGS !
 row.uniq_id = uuid.uuid4()
 row.save(update_fields=['uniq_id']) # .save(using='foobar', ...)
 -- HANGS with database routers !

 class Migration(migrations.Migration):
 dependencies = [
 ('myapp', '003_previous_migration'),
 ]

 operations = [
 migrations.AddField(
 model_name='customuser',
 name='uniq_id',
 field=models.UUIDField(default=uuid.uuid4, null=True),
 ),
 migrations.RunPython(gen_uuid,
 reverse_code=migrations.RunPython.noop),
 migrations.AlterField(
 model_name='customuser',
 name='uniq_id',
 field=models.UUIDField(default=uuid.uuid4, unique=True),
 ),
 ]
 }}}

-- 
Ticket URL: 
Django 
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/048.7ff64dc8eb0546c078656a941c830f0c%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.