From 215d69ff718b683d2eaa923783cd068b127c4710 Mon Sep 17 00:00:00 2001
From: Nicolas ROCHE <nroche@entrouvert.com>
Date: Fri, 16 Apr 2021 16:27:50 +0200
Subject: [PATCH] misc: remove postgres.E003 warnings (#52028)

---
 .../apps/cartads_cs/migrations/0002_cartadsdatacache.py   | 4 ++--
 .../migrations/0004_cartadsdossier_cartads_steps_cache.py | 2 +-
 .../migrations/0011_cartadsdossier_cartads_cache_infos.py | 2 +-
 passerelle/apps/cartads_cs/models.py                      | 8 ++++----
 .../apps/choosit/migrations/0010_auto_20210202_1304.py    | 3 ++-
 .../apps/mobyt/migrations/0009_auto_20210202_1304.py      | 3 ++-
 .../apps/orange/migrations/0009_auto_20210202_1304.py     | 3 ++-
 passerelle/apps/ovh/migrations/0013_auto_20210202_1304.py | 3 ++-
 .../apps/oxyd/migrations/0009_auto_20210202_1304.py       | 3 ++-
 passerelle/apps/phonecalls/migrations/0001_initial.py     | 2 +-
 passerelle/apps/phonecalls/models.py                      | 2 +-
 .../apps/twilio/migrations/0002_auto_20210202_1304.py     | 3 ++-
 passerelle/base/models.py                                 | 6 +++---
 passerelle/sms/models.py                                  | 6 +++++-
 14 files changed, 30 insertions(+), 20 deletions(-)

diff --git a/passerelle/apps/cartads_cs/migrations/0002_cartadsdatacache.py b/passerelle/apps/cartads_cs/migrations/0002_cartadsdatacache.py
index 2c83fb82..b561bdac 100644
--- a/passerelle/apps/cartads_cs/migrations/0002_cartadsdatacache.py
+++ b/passerelle/apps/cartads_cs/migrations/0002_cartadsdatacache.py
@@ -16,14 +16,14 @@ class Migration(migrations.Migration):
         migrations.CreateModel(
             name='CartaDSDataCache',
             fields=[
                 (
                     'id',
                     models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
                 ),
                 ('data_type', models.CharField(max_length=50)),
-                ('data_parameters', django.contrib.postgres.fields.jsonb.JSONField(default={})),
-                ('data_values', django.contrib.postgres.fields.jsonb.JSONField(default={})),
+                ('data_parameters', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
+                ('data_values', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
                 ('last_update_datetime', models.DateTimeField(auto_now=True)),
             ],
         ),
     ]
diff --git a/passerelle/apps/cartads_cs/migrations/0004_cartadsdossier_cartads_steps_cache.py b/passerelle/apps/cartads_cs/migrations/0004_cartadsdossier_cartads_steps_cache.py
index 3676af4f..1842fe7b 100644
--- a/passerelle/apps/cartads_cs/migrations/0004_cartadsdossier_cartads_steps_cache.py
+++ b/passerelle/apps/cartads_cs/migrations/0004_cartadsdossier_cartads_steps_cache.py
@@ -11,11 +11,11 @@ class Migration(migrations.Migration):
     dependencies = [
         ('cartads_cs', '0003_cartadsdossier_name_id'),
     ]
 
     operations = [
         migrations.AddField(
             model_name='cartadsdossier',
             name='cartads_steps_cache',
-            field=django.contrib.postgres.fields.jsonb.JSONField(default={}),
+            field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
         ),
     ]
diff --git a/passerelle/apps/cartads_cs/migrations/0011_cartadsdossier_cartads_cache_infos.py b/passerelle/apps/cartads_cs/migrations/0011_cartadsdossier_cartads_cache_infos.py
index f87a508a..17f8dad8 100644
--- a/passerelle/apps/cartads_cs/migrations/0011_cartadsdossier_cartads_cache_infos.py
+++ b/passerelle/apps/cartads_cs/migrations/0011_cartadsdossier_cartads_cache_infos.py
@@ -11,11 +11,11 @@ class Migration(migrations.Migration):
     dependencies = [
         ('cartads_cs', '0010_cartadsdossier_cartads_cache_code_acces'),
     ]
 
     operations = [
         migrations.AddField(
             model_name='cartadsdossier',
             name='cartads_cache_infos',
-            field=django.contrib.postgres.fields.jsonb.JSONField(default={}),
+            field=django.contrib.postgres.fields.jsonb.JSONField(default=dict),
         ),
     ]
diff --git a/passerelle/apps/cartads_cs/models.py b/passerelle/apps/cartads_cs/models.py
index 5ac14102..0e4ac2ce 100644
--- a/passerelle/apps/cartads_cs/models.py
+++ b/passerelle/apps/cartads_cs/models.py
@@ -57,18 +57,18 @@ def cartads_file_location(instance, filename):
 
 
 def key_value_of_stringstring(d):
     return {'KeyValueOfstringstring': [{'Key': x, 'Value': y} for x, y in d.items()]}
 
 
 class CartaDSDataCache(models.Model):
     data_type = models.CharField(max_length=50)
-    data_parameters = JSONField(default={})
-    data_values = JSONField(default={})
+    data_parameters = JSONField(default=dict)
+    data_values = JSONField(default=dict)
     last_update_datetime = models.DateTimeField(auto_now=True)
 
 
 class CartaDSFile(models.Model):
     tracking_code = models.CharField(max_length=20)
     id_piece = models.CharField(max_length=20)
     uploaded_file = models.FileField(upload_to=cartads_file_location)
     sent_to_cartads = models.DateTimeField(null=True)
@@ -92,18 +92,18 @@ class CartaDSDossier(models.Model):
     zip_ready = models.BooleanField(default=False)
     zip_sent = models.BooleanField(default=False)
     zip_ack_response = models.CharField(null=True, max_length=20)
     notification_url = models.URLField(null=True)
     notification_message = models.TextField(null=True)
     cartads_id_dossier = models.CharField(max_length=50, null=True)
     cartads_numero_dossier = models.CharField(max_length=50, null=True)
     cartads_cache_code_acces = models.CharField(max_length=200, null=True)
-    cartads_cache_infos = JSONField(default={})
-    cartads_steps_cache = JSONField(default={})
+    cartads_cache_infos = JSONField(default=dict)
+    cartads_steps_cache = JSONField(default=dict)
     last_update_datetime = models.DateTimeField(auto_now=True)
     subscribers = models.ManyToManyField(CartaDSSubscriber, blank=True)
     formdata_url = models.CharField(null=True, max_length=200)
 
 
 class AbstractCartaDSCS(BaseResource):
 
     wsdl_base_url = models.URLField(
diff --git a/passerelle/apps/choosit/migrations/0010_auto_20210202_1304.py b/passerelle/apps/choosit/migrations/0010_auto_20210202_1304.py
index e29cef95..1792f1c4 100644
--- a/passerelle/apps/choosit/migrations/0010_auto_20210202_1304.py
+++ b/passerelle/apps/choosit/migrations/0010_auto_20210202_1304.py
@@ -1,14 +1,15 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.18 on 2021-02-02 12:04
 from __future__ import unicode_literals
 
 import django.contrib.postgres.fields
 from django.db import migrations, models
+import passerelle.sms.models
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('choosit', '0009_choositsmsgateway_max_message_length'),
     ]
 
@@ -31,14 +32,14 @@ class Migration(migrations.Migration):
                         ('fr-metro', 'France mainland (+33 [67])'),
                         ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
                         ('be', 'Belgian (+32 4[5-9]) '),
                         ('all', 'All'),
                     ],
                     max_length=32,
                     null=True,
                 ),
-                default=['all'],
+                default=passerelle.sms.models.authorized_default,
                 size=None,
                 verbose_name='Authorized Countries',
             ),
         ),
     ]
diff --git a/passerelle/apps/mobyt/migrations/0009_auto_20210202_1304.py b/passerelle/apps/mobyt/migrations/0009_auto_20210202_1304.py
index d5f79f8e..47f7c25c 100644
--- a/passerelle/apps/mobyt/migrations/0009_auto_20210202_1304.py
+++ b/passerelle/apps/mobyt/migrations/0009_auto_20210202_1304.py
@@ -1,14 +1,15 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.18 on 2021-02-02 12:04
 from __future__ import unicode_literals
 
 import django.contrib.postgres.fields
 from django.db import migrations, models
+import passerelle.sms.models
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('mobyt', '0008_auto_20200310_1539'),
     ]
 
@@ -31,14 +32,14 @@ class Migration(migrations.Migration):
                         ('fr-metro', 'France mainland (+33 [67])'),
                         ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
                         ('be', 'Belgian (+32 4[5-9]) '),
                         ('all', 'All'),
                     ],
                     max_length=32,
                     null=True,
                 ),
-                default=['all'],
+                default=passerelle.sms.models.authorized_default,
                 size=None,
                 verbose_name='Authorized Countries',
             ),
         ),
     ]
diff --git a/passerelle/apps/orange/migrations/0009_auto_20210202_1304.py b/passerelle/apps/orange/migrations/0009_auto_20210202_1304.py
index 23dee944..0ea1bc6a 100644
--- a/passerelle/apps/orange/migrations/0009_auto_20210202_1304.py
+++ b/passerelle/apps/orange/migrations/0009_auto_20210202_1304.py
@@ -1,14 +1,15 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.18 on 2021-02-02 12:04
 from __future__ import unicode_literals
 
 import django.contrib.postgres.fields
 from django.db import migrations, models
+import passerelle.sms.models
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('orange', '0008_auto_20200412_1240'),
     ]
 
@@ -31,14 +32,14 @@ class Migration(migrations.Migration):
                         ('fr-metro', 'France mainland (+33 [67])'),
                         ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
                         ('be', 'Belgian (+32 4[5-9]) '),
                         ('all', 'All'),
                     ],
                     max_length=32,
                     null=True,
                 ),
-                default=['all'],
+                default=passerelle.sms.models.authorized_default,
                 size=None,
                 verbose_name='Authorized Countries',
             ),
         ),
     ]
diff --git a/passerelle/apps/ovh/migrations/0013_auto_20210202_1304.py b/passerelle/apps/ovh/migrations/0013_auto_20210202_1304.py
index 43520975..90a77683 100644
--- a/passerelle/apps/ovh/migrations/0013_auto_20210202_1304.py
+++ b/passerelle/apps/ovh/migrations/0013_auto_20210202_1304.py
@@ -1,14 +1,15 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.18 on 2021-02-02 12:04
 from __future__ import unicode_literals
 
 import django.contrib.postgres.fields
 from django.db import migrations, models
+import passerelle.sms.models
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('ovh', '0012_auto_20201027_1121'),
     ]
 
@@ -31,17 +32,17 @@ class Migration(migrations.Migration):
                         ('fr-metro', 'France mainland (+33 [67])'),
                         ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
                         ('be', 'Belgian (+32 4[5-9]) '),
                         ('all', 'All'),
                     ],
                     max_length=32,
                     null=True,
                 ),
-                default=['all'],
+                default=passerelle.sms.models.authorized_default,
                 size=None,
                 verbose_name='Authorized Countries',
             ),
         ),
         migrations.AlterField(
             model_name='ovhsmsgateway',
             name='alert_emails',
             field=django.contrib.postgres.fields.ArrayField(
diff --git a/passerelle/apps/oxyd/migrations/0009_auto_20210202_1304.py b/passerelle/apps/oxyd/migrations/0009_auto_20210202_1304.py
index 23ef8f2d..d7e4d8ac 100644
--- a/passerelle/apps/oxyd/migrations/0009_auto_20210202_1304.py
+++ b/passerelle/apps/oxyd/migrations/0009_auto_20210202_1304.py
@@ -1,14 +1,15 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.18 on 2021-02-02 12:04
 from __future__ import unicode_literals
 
 import django.contrib.postgres.fields
 from django.db import migrations, models
+import passerelle.sms.models
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('oxyd', '0008_oxydsmsgateway_max_message_length'),
     ]
 
@@ -31,14 +32,14 @@ class Migration(migrations.Migration):
                         ('fr-metro', 'France mainland (+33 [67])'),
                         ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
                         ('be', 'Belgian (+32 4[5-9]) '),
                         ('all', 'All'),
                     ],
                     max_length=32,
                     null=True,
                 ),
-                default=['all'],
+                default=passerelle.sms.models.authorized_default,
                 size=None,
                 verbose_name='Authorized Countries',
             ),
         ),
     ]
diff --git a/passerelle/apps/phonecalls/migrations/0001_initial.py b/passerelle/apps/phonecalls/migrations/0001_initial.py
index 0ed310c6..1152ea49 100644
--- a/passerelle/apps/phonecalls/migrations/0001_initial.py
+++ b/passerelle/apps/phonecalls/migrations/0001_initial.py
@@ -22,17 +22,17 @@ class Migration(migrations.Migration):
                 (
                     'id',
                     models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID'),
                 ),
                 ('callee', models.CharField(max_length=64)),
                 ('caller', models.CharField(max_length=64)),
                 ('start_timestamp', models.DateTimeField(auto_now_add=True)),
                 ('end_timestamp', models.DateTimeField(default=None, null=True)),
-                ('details', django.contrib.postgres.fields.jsonb.JSONField(default={})),
+                ('details', django.contrib.postgres.fields.jsonb.JSONField(default=dict)),
             ],
             options={
                 'ordering': ['-start_timestamp'],
                 'verbose_name': 'Phone Call',
             },
         ),
         migrations.CreateModel(
             name='PhoneCalls',
diff --git a/passerelle/apps/phonecalls/models.py b/passerelle/apps/phonecalls/models.py
index 0fb98484..fbfffeb6 100644
--- a/passerelle/apps/phonecalls/models.py
+++ b/passerelle/apps/phonecalls/models.py
@@ -145,17 +145,17 @@ class PhoneCalls(BaseResource):
 
 
 class Call(models.Model):
     resource = models.ForeignKey(PhoneCalls, on_delete=models.CASCADE)
     callee = models.CharField(blank=False, max_length=64)
     caller = models.CharField(blank=False, max_length=64)
     start_timestamp = models.DateTimeField(auto_now_add=True)
     end_timestamp = models.DateTimeField(null=True, default=None)
-    details = JSONField(default={})
+    details = JSONField(default=dict)
 
     class Meta:
         verbose_name = _('Phone Call')
         ordering = ['-start_timestamp']
 
     def json(self):
         # We use make_naive to send localtime, because this API will be used
         # by javascript, which will not be comfortable with UTC datetimes
diff --git a/passerelle/apps/twilio/migrations/0002_auto_20210202_1304.py b/passerelle/apps/twilio/migrations/0002_auto_20210202_1304.py
index 0e1d388b..0a410cbe 100644
--- a/passerelle/apps/twilio/migrations/0002_auto_20210202_1304.py
+++ b/passerelle/apps/twilio/migrations/0002_auto_20210202_1304.py
@@ -1,14 +1,15 @@
 # -*- coding: utf-8 -*-
 # Generated by Django 1.11.18 on 2021-02-02 12:04
 from __future__ import unicode_literals
 
 import django.contrib.postgres.fields
 from django.db import migrations, models
+import passerelle.sms.models
 
 
 class Migration(migrations.Migration):
 
     dependencies = [
         ('twilio', '0001_initial'),
     ]
 
@@ -31,14 +32,14 @@ class Migration(migrations.Migration):
                         ('fr-metro', 'France mainland (+33 [67])'),
                         ('fr-domtom', 'France DOM/TOM (+262, etc.)'),
                         ('be', 'Belgian (+32 4[5-9]) '),
                         ('all', 'All'),
                     ],
                     max_length=32,
                     null=True,
                 ),
-                default=['all'],
+                default=passerelle.sms.models.authorized_default,
                 size=None,
                 verbose_name='Authorized Countries',
             ),
         ),
     ]
diff --git a/passerelle/base/models.py b/passerelle/base/models.py
index e54a1f1d..c35f9445 100644
--- a/passerelle/base/models.py
+++ b/passerelle/base/models.py
@@ -755,33 +755,33 @@ class SkipJob(Exception):
 
 
 class Job(models.Model):
     resource_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
     resource_pk = models.PositiveIntegerField()
     resource = fields.GenericForeignKey('resource_type', 'resource_pk')
     method_name = models.CharField(max_length=50)
     natural_id = models.CharField(max_length=256, blank=True, null=True)
-    parameters = JSONField(default={})
+    parameters = JSONField(default=dict)
     creation_timestamp = models.DateTimeField(auto_now_add=True)
     update_timestamp = models.DateTimeField(auto_now=True)
     done_timestamp = models.DateTimeField(null=True)
     after_timestamp = models.DateTimeField(null=True)
     status = models.CharField(
         max_length=20,
         default='registered',
         choices=(
             ('registered', _('Registered')),
             ('running', _('Running')),
             ('failed', _('Failed')),
             ('restarted', _('Failed and restarted')),
             ('completed', _('Completed')),
         ),
     )
-    status_details = JSONField(default={})
+    status_details = JSONField(default=dict)
 
     class Meta:
         ordering = ('id',)
 
     def set_after_timestamp(self, value):
         if isinstance(value, datetime.datetime):
             self.after_timestamp = value
         elif isinstance(value, six.integer_types + (float,)):
@@ -836,17 +836,17 @@ class Job(models.Model):
 @six.python_2_unicode_compatible
 class ResourceLog(models.Model):
     timestamp = models.DateTimeField(auto_now_add=True)
     appname = models.CharField(max_length=128, verbose_name='appname', null=True)
     slug = models.CharField(max_length=128, verbose_name='slug', null=True)
     levelno = models.IntegerField(verbose_name='log level')
     sourceip = models.GenericIPAddressField(blank=True, null=True, verbose_name=_('Source IP'))
     message = models.TextField(verbose_name='message')
-    extra = JSONField(verbose_name='extras', default={})
+    extra = JSONField(verbose_name='extras', default=dict)
     transaction_id = models.UUIDField(null=True, db_index=True)
 
     class Meta:
         ordering = ('id',)
         permissions = (('see_resourcelog', 'Can see resource logs'),)
 
     @property
     def level(self):
diff --git a/passerelle/sms/models.py b/passerelle/sms/models.py
index db86dec8..7df1c86e 100644
--- a/passerelle/sms/models.py
+++ b/passerelle/sms/models.py
@@ -46,16 +46,20 @@ SEND_SCHEMA = {
             'description': 'Destination numbers',
             "type": "array",
             "items": {'type': 'string', 'pattern': r'^\+?[-.\s/\d]+$'},
         },
     },
 }
 
 
+def authorized_default():
+    return [SMSResource.ALL]
+
+
 class SMSResource(BaseResource):
     manager_form_base_class = SMSConnectorForm
     category = _('SMS Providers')
     documentation_url = (
         'https://doc-publik.entrouvert.com/admin-fonctionnel/les-tutos/configuration-envoi-sms/'
     )
 
     _can_send_messages_description = _('Sending messages is limited to the following API users:')
@@ -78,17 +82,17 @@ class SMSResource(BaseResource):
         (FR_METRO, _('France mainland (+33 [67])')),
         (FR_DOMTOM, _('France DOM/TOM (+262, etc.)')),
         (BE_, _('Belgian (+32 4[5-9]) ')),
         (ALL, _('All')),
     ]
     authorized = ArrayField(
         models.CharField(max_length=32, null=True, choices=AUTHORIZED),
         verbose_name=_('Authorized Countries'),
-        default=[ALL],
+        default=authorized_default,
     )
 
     allow_premium_rate = models.BooleanField(
         _('Allow premium rate numbers'),
         default=False,
         help_text=_('This option is only applyed to France mainland'),
     )
 
-- 
2.30.2

