cubicweb-trackervcs #1832821 PatchRevisionAdded hook breaks if the patch->ticket relation already exists [resolved]

Importing a new patch revision can result in the following trace when the patch/ticket relation is already in place:

2011-07-19 11:58:58 - (cubicweb.sources.system) CRITICAL: sql many: 'INSERT INTO patch_ticket_relation ( eid_to, eid_from ) VALUES ( %(eid_to)s, %(eid_from)s )'
args: [{'eid_to': 68057, 'eid_from': 78116}]
dbms message: 'duplicate key value violates unique constraint "patch_ticket_relation_p_key"\n'
2011-07-19 11:58:58 - (cubicweb.sources.system) CRITICAL: transaction has been rollbacked
2011-07-19 11:58:58 - (cubicweb.session) DEBUG: rollback for session internal done
2011-07-19 11:58:58 - (cubicweb.sources.hg) ERROR: error while importing content for vcs repo pylint patches
Traceback (most recent call last):
File "/home/jcr/src/cw/cubes/vcsfile/bridge.py", line 101, in import_vcsrepo_content
repohdlr.import_content(vcsrepo, commitevery)
File "/home/jcr/src/cw/cubes/vcsfile/repohg.py", line 131, in import_content
session.commit()
File "/home/jcr/src/cw/cubicweb/server/session.py", line 967, in commit
operation.handle_event('precommit_event')
File "/home/jcr/src/cw/cubicweb/server/hook.py", line 812, in handle_event
getattr(self, event)()
File "/home/jcr/src/cw/cubes/vcreview/hooks.py", line 60, in precommit_event
patch.set_relations(patch_revision=entity)
File "/home/jcr/src/cw/cubicweb/entity.py", line 1016, in set_relations
restr, ','.join(eids)), {'x': self.eid})
File "/home/jcr/src/cw/cubicweb/server/session.py", line 897, in execute
rset = self._execute(self, rql, kwargs, build_descr)
File "/home/jcr/src/cw/cubicweb/server/querier.py", line 731, in execute
results = plan.execute()
File "/home/jcr/src/cw/cubicweb/server/querier.py", line 202, in execute
result = step.execute()
File "/home/jcr/src/cw/cubicweb/server/ssplanner.py", line 582, in execute
repo.glob_add_relations(session, relations)
File "/home/jcr/src/cw/cubicweb/server/repository.py", line 1474, in glob_add_relations
rtype=rtype, eids_from_to=source_relations)
File "/home/jcr/src/cw/cubicweb/server/hook.py", line 415, in call_hooks
registry.call_hooks(event, session, **kwargs)
File "/home/jcr/src/cw/cubicweb/server/hook.py", line 337, in call_hooks
hook()
File "/home/jcr/src/cw/cubes/trackervcs/hooks.py", line 144, in __call__
patch.set_relations(patch_ticket=ticket)
File "/home/jcr/src/cw/cubicweb/entity.py", line 1016, in set_relations
restr, ','.join(eids)), {'x': self.eid})
File "/home/jcr/src/cw/cubicweb/server/session.py", line 897, in execute
rset = self._execute(self, rql, kwargs, build_descr)
File "/home/jcr/src/cw/cubicweb/server/querier.py", line 731, in execute
results = plan.execute()
File "/home/jcr/src/cw/cubicweb/server/querier.py", line 202, in execute
result = step.execute()
File "/home/jcr/src/cw/cubicweb/server/ssplanner.py", line 582, in execute
repo.glob_add_relations(session, relations)
File "/home/jcr/src/cw/cubicweb/server/repository.py", line 1467, in glob_add_relations
source.add_relations(session, rtype, source_relations)
File "/home/jcr/src/cw/cubicweb/server/sources/native.py", line 679, in add_relations
self._add_relations(session, rtype, subj_obj_list, inlined)
File "/home/jcr/src/cw/cubicweb/server/sources/native.py", line 707, in _add_relations
self.doexecmany(session, statement, attrs)
File "/home/jcr/src/cw/cubicweb/server/sources/native.py", line 783, in doexecmany
cursor.executemany(str(query), args)
IntegrityError: duplicate key value violates unique constraint "patch_ticket_relation_p_key"

prioritynormal
typebug
done in0.6.1
load left0.000
closed by#81d5105bff28 hooks: don't add an already existing patch_ticket relation (closes #1832821)