[GeoNode-users] IntegrityError: duplicate key value violates unique constraint "base_hierarchicalkeyword_name_key"

Gavin Reich Gavin.Reich at michaelcarder.co.uk
Mon Sep 26 08:51:46 PDT 2016


Hi all,

I'm encountering an error related to Hierarchical Keywords when trying to add a layer to geonode using file_upload(). The h_keyword ("human health") has already been added previously when adding another layer. I'm not sure if this is a bug in _HierarchicalTagManager.add()? https://github.com/GeoNode/geonode/blob/master/geonode/base/models.py#L276

Any help would be appreciated

Thanks
Gavin

>>> layer = file_upload(filename='/home/ec2-user/test/ospar_encounters_2012_01.shp', name='Encounters2012', user=ospar, abstract='encounters 2012 test', overwrite=True, metadata_uploaded_preserve=True)
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/opt/python/run/venv/src/geonode/geonode/layers/utils.py", line 514, in file_upload
    layer.keywords.add(*keywords)
  File "/opt/python/run/venv/src/geonode/geonode/base/models.py", line 291, in add
    tag_objs.add(HierarchicalKeyword.add_root(name=new_tag))
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/treebeard/mp_tree.py", line 593, in add_root
    return MP_AddRootHandler(cls, **kwargs).process()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/treebeard/mp_tree.py", line 295, in process
    return last_root.add_sibling('sorted-sibling', **self.kwargs)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/treebeard/mp_tree.py", line 982, in add_sibling
    return MP_AddSiblingHandler(self, pos, **kwargs).process()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/treebeard/mp_tree.py", line 420, in process
    newobj.save()
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/taggit/models.py", line 86, in save
    return super(TagBase, self).save(*args, **kwargs)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 734, in save
    force_update=force_update, update_fields=update_fields)
  File "/opt/python/run/venv/local/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 "/opt/python/run/venv/local/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 "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/base.py", line 885, in _do_insert
    using=using, raw=raw)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/manager.py", line 127, in manager_method
    return getattr(self.get_queryset(), name)(*args, **kwargs)
  File "/opt/python/run/venv/local/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 "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/models/sql/compiler.py", line 974, in execute_sql
    cursor.execute(sql, params)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 79, in execute
    return super(CursorDebugWrapper, self).execute(sql, params)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/utils.py", line 98, in __exit__
    six.reraise(dj_exc_type, dj_exc_value, traceback)
  File "/opt/python/run/venv/local/lib/python2.7/site-packages/django/db/backends/utils.py", line 64, in execute
    return self.cursor.execute(sql, params)
IntegrityError: duplicate key value violates unique constraint "base_hierarchicalkeyword_name_key"
DETAIL:  Key (name)=(human health) already exists.


The snippet of the xml metadata containing the keywords:

<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<gmd:keyword>
<gco:CharacterString>Human health and safety</gco:CharacterString>
</gmd:keyword>
<gmd:thesaurusName>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>GEMET - INSPIRE themes, version 1.0</gco:CharacterString>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>2010-01-13</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#CI_DateTypeCode" codeListValue="publication">publication</gmd:CI_DateTypeCode>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</gmd:CI_Citation>
</gmd:thesaurusName>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>
<gmd:descriptiveKeywords>
<gmd:MD_Keywords>
<gmd:keyword>
<gco:CharacterString>human health</gco:CharacterString>
</gmd:keyword>
<gmd:thesaurusName>
<gmd:CI_Citation>
<gmd:title>
<gco:CharacterString>GEMET - Themes, version 2.4</gco:CharacterString>
</gmd:title>
<gmd:date>
<gmd:CI_Date>
<gmd:date>
<gco:Date>2010-01-13</gco:Date>
</gmd:date>
<gmd:dateType>
<gmd:CI_DateTypeCode codeList="http://standards.iso.org/ittf/PubliclyAvailableStandards/ISO_19139_Schemas/resources/Codelist/ML_gmxCodelists.xml#CI_DateTypeCode" codeListValue="publication">publication</gmd:CI_DateTypeCode>
</gmd:dateType>
</gmd:CI_Date>
</gmd:date>
</gmd:CI_Citation>
</gmd:thesaurusName>
</gmd:MD_Keywords>
</gmd:descriptiveKeywords>

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osgeo.org/pipermail/geonode-users/attachments/20160926/7c43dd86/attachment.html>


More information about the geonode-users mailing list