Skip to content

Conversation

jpic
Copy link
Member

@jpic jpic commented May 25, 2016

No description provided.

jpic added 2 commits May 25, 2016 09:45
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']
Copy link
Member

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 ?)

@jpic jpic force-pushed the francedata_fixes branch from 8f45378 to 2d20fde Compare May 26, 2016 22:24
@@ -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']
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Commit no longer needed

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants