-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Francedata fixes #27
base: master
Are you sure you want to change the base?
Francedata fixes #27
Conversation
So a duplicate fingerprint would fail to pass unique test. Fixes: + francedata_import_representatives cTraceback (most recent call last): File "/home/jpic/work/lqdn/lqdn_env/bin/francedata_import_representatives", line 9, in <module> load_entry_point('django-representatives==0.0.19', 'console_scripts', 'francedata_import_representatives')() File "/home/jpic/work/lqdn/django-representatives/representatives/contrib/francedata/import_representatives.py", line 317, in main an_importer.manage_rep(rep) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/utils/decorators.py", line 145, in inner return func(*args, **kwargs) File "/home/jpic/work/lqdn/django-representatives/representatives/contrib/francedata/import_representatives.py", line 145, in manage_rep self.add_mandates(representative, rep_json) File "/home/jpic/work/lqdn/django-representatives/representatives/contrib/francedata/import_representatives.py", line 184, in add_mandates name=rep_json.get('parti_ratt_financier'), country=self.france) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/query.py", line 407, in get_or_create return self._create_object_from_params(lookup, params) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/query.py", line 447, in _create_object_from_params six.reraise(*exc_info) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/query.py", line 439, in _create_object_from_params obj = self.create(**params) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/query.py", line 348, in create obj.save(force_insert=True, using=self.db) File "/home/jpic/work/lqdn/django-representatives/representatives/models.py", line 68, in save super(HashableModel, self).save(*args, **kwargs) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/base.py", line 734, in save force_update=force_update, update_fields=update_fields) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/base.py", line 762, in save_base updated = self._save_table(raw, cls, force_insert, force_update, using, update_fields) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/base.py", line 846, in _save_table result = self._do_insert(cls._base_manager, using, fields, update_pk, raw) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/base.py", line 885, in _do_insert using=using, raw=raw) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method return getattr(self.get_queryset(), name)(*args, **kwargs) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/query.py", line 920, in _insert return query.get_compiler(using=using).execute_sql(return_id) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 974, in execute_sql cursor.execute(sql, params) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__ six.reraise(dj_exc_type, dj_exc_value, traceback) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute return self.cursor.execute(sql, params) File "/home/jpic/work/lqdn/lqdn_env/lib/python2.7/site-packages/django/db/backends/sqlite3/base.py", line 318, in execute return Database.Cursor.execute(self, query, params) django.db.utils.IntegrityError: UNIQUE constraint failed: representatives_constituency.fingerprint
@@ -175,6 +175,11 @@ class Chamber(HashableModel): | |||
|
|||
hashable_fields = ['name', 'country', 'abbreviation'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Couldn't we get rid of hashable_fields and use the metaclass unique_together attribute in HashableModel.compute_hash ? That would avoid duplicating code.
(also is Meta.unique_together parsed by django-admin makemigrations ? or do we have to create the migration manually ?)
@@ -219,7 +219,7 @@ class Constituency(HashableModel, TimeStampedModel): | |||
country = models.ForeignKey('Country', null=True, blank=True, | |||
related_name='constituencies') | |||
|
|||
hashable_fields = ['name'] | |||
hashable_fields = ['name', 'country'] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Commit no longer needed
No description provided.