Skip to content

collectoss.tasks.github.events.collect_events: duplicate key value violates unique constraint "issue-insert-unique" #151

Open

Description

@collectoss-issue-migrator

Note

Migrated from augurlabs/augur#3457
Originally opened by @cdolfi on 2025-12-11


I think this error will get solved the same way as #93

IntegrityError('(psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "issue-insert-unique"\nDETAIL: Key (issue_url)=(https://api.github.com/repos/pulp/pulp-ui/issues/1) already exists.\n')

Stack Trace
Traceback (most recent call last):
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1938, in _exec_single_context
    self.dialect.do_executemany(
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 794, in do_executemany
    cursor.executemany(statement, parameters)
psycopg2.errors.UniqueViolation: duplicate key value violates unique constraint "issue-insert-unique"
DETAIL:  Key (issue_url)=(https://api.github.com/repos/pulp/pulp-ui/issues/1) already exists.


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/augur/.venv/lib/python3.11/site-packages/celery/app/trace.py", line 453, in trace_task
    R = retval = fun(*args, **kwargs)
                 ^^^^^^^^^^^^^^^^^^^^
  File "/augur/.venv/lib/python3.11/site-packages/celery/app/trace.py", line 736, in __protected_call__
    return self.run(*args, **kwargs)
           ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/augur/augur/tasks/github/events.py", line 46, in collect_events
    collection_strategy.collect(repo_git, key_auth, core_data_last_collected)
  File "/augur/augur/tasks/github/events.py", line 128, in collect
    self._process_events(events, repo_id)
  File "/augur/augur/tasks/github/events.py", line 167, in _process_events
    update_issue_closed_cntrbs_by_repo_id(repo_id)
  File "/augur/augur/application/db/lib.py", line 555, in update_issue_closed_cntrbs_by_repo_id
    connection.execute(update_stmt, update_data)
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1416, in execute
    return meth(
           ^^^^^
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/sql/elements.py", line 516, in _execute_on_connection
    return connection._execute_clauseelement(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1639, in _execute_clauseelement
    ret = self._execute_context(
          ^^^^^^^^^^^^^^^^^^^^^^
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1848, in _execute_context
    return self._exec_single_context(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1988, in _exec_single_context
    self._handle_dbapi_exception(
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 2343, in _handle_dbapi_exception
    raise sqlalchemy_exception.with_traceback(exc_info[2]) from e
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/engine/base.py", line 1938, in _exec_single_context
    self.dialect.do_executemany(
  File "/augur/.venv/lib/python3.11/site-packages/sqlalchemy/dialects/postgresql/psycopg2.py", line 794, in do_executemany
    cursor.executemany(statement, parameters)
sqlalchemy.exc.IntegrityError: (psycopg2.errors.UniqueViolation) duplicate key value violates unique constraint "issue-insert-unique"
DETAIL:  Key (issue_url)=(https://api.github.com/repos/pulp/pulp-ui/issues/1) already exists.

[SQL: 
                UPDATE issues
                SET cntrb_id = %(cntrb_id)s
                WHERE issue_id = %(issue_id)s
                AND repo_id = %(repo_id)s
            ]
[parameters: [{'cntrb_id': UUID('01035995-d400-0000-0000-000000000000'), 'issue_id': 428805, 'repo_id': 27505}, {'cntrb_id': UUID('01035995-d400-0000-0000-000000000000'), 'issue_id': 428816, 'repo_id': 27505}, {'cntrb_id': UUID('0100047d-c300-0000-0000-000000000000'), 'issue_id': 428821, 'repo_id': 27505}, {'cntrb_id': UUID('01035995-d400-0000-0000-000000000000'), 'issue_id': 428823, 'repo_id': 27505}, {'cntrb_id': UUID('0101724c-7f00-0000-0000-000000000000'), 'issue_id': 212279091, 'repo_id': 27505}, {'cntrb_id': UUID('0100046b-cf00-0000-0000-000000000000'), 'issue_id': 212279092, 'repo_id': 27505}, {'cntrb_id': UUID('0100046b-cf00-0000-0000-000000000000'), 'issue_id': 212279102, 'repo_id': 27505}, {'cntrb_id': UUID('01008560-6200-0000-0000-000000000000'), 'issue_id': 212279103, 'repo_id': 27505}  ... displaying 10 of 23 total bound parameter sets ...  {'cntrb_id': UUID('0100046b-cf00-0000-0000-000000000000'), 'issue_id': 239085787, 'repo_id': 27505}, {'cntrb_id': UUID('010058be-8500-0000-0000-000000000000'), 'issue_id': 239085788, 'repo_id': 27505}]]
(Background on this error at: https://sqlalche.me/e/20/gkpj)

https://github.com/pulp/pulp-ui'

Activity

  1. collectoss-issue-migrator commented on Apr 30, 2026

    @collectoss-issue-migrator
    Author

    Note

    Migrated comment from original
    Originally posted by @mn-ram on 2026-03-27


    Hi @cdolfi @MoralCode — opened PR augurlabs/augur#3801 to fix this.

    The UPDATE in update_issue_closed_cntrbs_by_repo_id was using engine.connect() instead of engine.begin(), so the transaction was never committed in SQLAlchemy 2.0. One-line fix — matches the pattern used everywhere else in lib.py (lines 78, 88, 384, 426).

  2. added
    bug
    deployed version
    on Apr 30, 2026
  3. collectoss-issue-migrator commented on Apr 30, 2026

    @collectoss-issue-migrator
    Author

    Note

    Migrated comment from original
    Originally posted by @MoralCode on 2026-03-27


    I responded in the PR

  4. collectoss-issue-migrator commented on Apr 30, 2026

    @collectoss-issue-migrator
    Author

    Note

    Migrated comment from original
    Originally posted by @MoralCode on 2026-03-28


    after reviewing the PR mentioned above, it is not a fix for this issue, even though the stack trace points directly to the query being run, its not actually that query that is causing the issue because that query never touches the issue_url, so it couldnt possibly cause this unique violation.

    however, analysis by Gemini has led me to what may be the true cause of the issue

    SELECT issue_url, COUNT(*) 
    FROM augur_data.issues 
    GROUP BY issue_url 
    HAVING COUNT(*) > 1;

    duplicate urls already exist in the table (somehow) despite the constraint existing. There are about 528 of them, meaning about 215 or so records with duplicate urls. I imagine these must have existed before the constraint was in place and somehow slipped under the radar.

    The below query reveals the affected records in more detail

    SELECT 
        issue_id, 
        issue_url, 
        repo_id, 
        cntrb_id, 
        created_at,
        tool_source,
        COUNT(*) OVER(PARTITION BY issue_url) as occurrence_count
    FROM augur_data.issues
    WHERE issue_url IN (
        SELECT issue_url 
        FROM augur_data.issues 
        GROUP BY issue_url 
        HAVING COUNT(*) > 1
    )
    ORDER BY issue_url, issue_id;
  5. changed the title [-]augur.tasks.github.events.collect_events: duplicate key value violates unique constraint "issue-insert-unique"[/-] [+]collectoss.tasks.github.events.collect_events: duplicate key value violates unique constraint "issue-insert-unique"[/+] on May 5, 2026
  6. self-assigned this
    on May 21, 2026
  7. MoralCode commented on May 29, 2026

    @MoralCode
    Contributor

    can confirm no more duplicates are present in the database. Unable to confirm 100% if this task is still failing because pulp/pulp-ui is affected by the other similar (PR related) issue, and thus collect_events is not yet being scheduled in flower.

    The IDs for a random pulp ui PR number i picked (20) do seem to check out though

    Logic walk through
    select * from augur_data.pull_requests pr
    where pr.pr_url = 'https://api.github.com/repos/pulp/pulp-ui/pulls/20';

    pr_src_id 1968684185
    node id PR_kwDOMJXKcc51V7yZ

    select * from augur_data.repo r 
    where r.repo_git = 'https://github.com/pulp/pulp-ui';

    repo src id 815123057

    https://api.github.com/repos/pulp/pulp-ui/pulls/20
    id 1968684185
    node_id "PR_kwDOMJXKcc51V7yZ"
    base.repo.id 815123057

  8. added theissue type on Jun 24, 2026
  9. added
    critical-fix
    on Sep 29, 2026
  10. MoralCode commented on Oct 30, 2026

    @MoralCode
    Contributor

    my queries above no longer seem to return any data (a good sign - the conflict i think exists seems to no longer).

    Queries (updated to the new schema names)
    SELECT issue_url, COUNT(*) 
    FROM data.issues 
    GROUP BY issue_url 
    HAVING COUNT(*) > 1;
    
    SELECT 
        issue_id, 
        issue_url, 
        repo_id, 
        cntrb_id, 
        created_at,
        tool_source,
        COUNT(*) OVER(PARTITION BY issue_url) as occurrence_count
    FROM data.issues
    WHERE issue_url IN (
        SELECT issue_url 
        FROM data.issues 
        GROUP BY issue_url 
        HAVING COUNT(*) > 1
    )
    ORDER BY issue_url, issue_id;
    
  11. MoralCode commented on Nov 19, 2026

    @MoralCode
    Contributor

    I think this PR may need a similar resolution as was proposed in #580 (once #575 lands)

  12. MoralCode commented on Nov 20, 2026

    @MoralCode
    Contributor

    This will likely be solved in a similar way to #93 (via the above mentioned PRs), but that hasnt landed yet, so this is blocked

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Labels

bugcritical-fixdeployed version

Type

Projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions